microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.47k stars 241 forks source link

warning fix #571

Closed Jbudone closed 4 days ago

Jbudone commented 1 year ago

Fix non-trivial copy assignment warning in memset usage

make: Entering directory '/home/jbud/repositories/node-pty/build'
  CXX(target) Release/obj.target/pty/src/unix/pty.o
../src/unix/pty.cc: In function ‘void pty_after_waitpid(uv_async_t*)’:
../src/unix/pty.cc:534:9: warning: ‘void* memset(void*, int, size_t)’ writing to an object of type ‘class Nan::Persistent<v8::Function>’ with no trivial copy-assignment [-Wclass-memaccess]
  534 |   memset(&baton->cb, -1, sizeof(baton->cb));
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tyriar commented 1 year ago

@deepak1556 is this just suppressing the warning? I see https://stackoverflow.com/a/66596764/1156119 recommends against it

deepak1556 commented 1 year ago

I would recommend using v8::NonCopyablePersistentTraits instead.

Jbudone commented 1 year ago

I don't quite understand :see_no_evil: How can I use v8::NonCopyablePersistentTraits here?

I tried changing the type here:

struct pty_baton {
  Nan::Persistent<v8::Function, v8::NonCopyablePersistentTraits<v8::Function>> cb;

But the warning persists:

make: Entering directory '/home/jbud/repositories/node-pty/build'
  CXX(target) Release/obj.target/pty/src/unix/pty.o
../src/unix/pty.cc: In function ‘void pty_after_waitpid(uv_async_t*)’:
../src/unix/pty.cc:534:9: warning: ‘void* memset(void*, int, size_t)’ writing to an object of type ‘class Nan::Persistent<v8::Function>’ with no trivial copy-assignment [-Wclass-memaccess]
  534 |   memset(&baton->cb, -1, sizeof(baton->cb));
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tyriar commented 4 days ago

Thing this was fixed with a different PR