node-pty icon indicating copy to clipboard operation
node-pty copied to clipboard

warning fix

Open Jbudone opened this issue 2 years ago • 3 comments
trafficstars

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));
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jbudone avatar Dec 03 '22 23:12 Jbudone

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

Tyriar avatar Dec 05 '22 12:12 Tyriar

I would recommend using v8::NonCopyablePersistentTraits instead.

deepak1556 avatar Dec 06 '22 02:12 deepak1556

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));
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jbudone avatar Dec 06 '22 05:12 Jbudone