0

Hi below code is crashing when i perform if check on argv[1]. Please help to fix it, while assigning the value to argv[1] i need to check if bool variable checktrue is true assign string value else assign int value as below code.

void DispatchEventWorker::HandleOKCallback() {
  v8::Local<v8::Value> argv[2];
    argv[0]= Nan::New<v8::String>(structdata.value1).ToLocalChecked();

if(checktrue)
     {
             argv[1] = Nan::New<v8::Number>(structdata.value2).ToLocalChecked();

     }
else
 {
          argv[1] = Nan::New<v8::String>(structdata.value3);
 }
  callback->Call(2, argv);
}

Note output : Process 123432098 (node) terminated SIGSEGV code=1 fltno=11 ip=0000000001076a08(/usr/lib/ldqnx-64.so.2@memcpy+0x0000000000000048) mapaddr=0000000000076a08. ref=2073696874206f74

mohan
  • 37
  • 3
  • hi, welcome to StackOverflow. We will gladly help you out but first you need to show some effort. Try to solve this issue on your own first, and edit this post to add your efforts. If you manage to solve this on your own don't forget to post an answer with the solution for the benefit of the rest of us. – bergerg Aug 12 '18 at 05:48
  • there was some typo mistake. Today is my first day in node js – mohan Aug 12 '18 at 08:17
  • (1) Formatting the code for readability would be nice. (2) The code does not match your description (regarding what to return in which case), which one is right? (3) You have two assignments to `argv[1]`, which one is the one that's crashing? (4) For working with C++, you should get familiar with a debugger. This will not be the last SIGSEGV you'll encounter ;-) – jmrk Aug 13 '18 at 11:20

1 Answers1

1

First, I suggest you always include the async_resource when calling back JS or otherwise some Node.js features won't work:

this->callback->Call(2, argv, this->async_resource);

Then, your code is missing a .ToLocalChecked() on argv[1] and does not compile in its current form.

Otherwise there is nothing fundamentally wrong with it and most probably the crash is not Node.js related - maybe one of these values is a null pointer.

mmomtchev
  • 2,497
  • 1
  • 8
  • 23