0

I wrote a piece of C++ code to connect with RFID reader using LLRP API on CentOS 7 system (64bit) and it has been working perfectly. I took that very .cpp file and copied it to my Ubuntu 14.04 desktop (64bit as well) and after "make" -ing the file it runs successfully.

The issue arises when I try to edit the .cpp file. Even insertion or deletion of a single character/ blank space/ comments results in a "segmentation fault (core dump)".

The .cpp file can be successfully saved and compiled via "make" after edits, but while running the executable using ./ segmentation fault arrives.

I am using simple gedit and vim nothing else.I am guessing the issue is related to how both operating systems handle the text characters. Any clues?

More observations ---

As per suggestions, I have tried by deleting all the codes and kept just -

int main()
{
}

And the code ran successfully. So what can be the issue now?

* MORE DETAILS *

Following is the code snippet that is under suspicion -
/*
     * Check to make sure the message is of the right type.
     * The type label (pointer) in the message should be
     * the type descriptor for READER_EVENT_NOTIFICATION.
     */
    if(&CREADER_EVENT_NOTIFICATION::s_typeDescriptor != pMessage->m_pType)
    {
        goto fail;
    }
printf("Hello from check\n");
    /*
     * Now that we are sure it is a READER_EVENT_NOTIFICATION,
     * traverse to the ReaderEventNotificationData parameter.
     */
    pNtf = (CREADER_EVENT_NOTIFICATION *) pMessage;
printf("Hello from check 2\n");
printf("Hello from check 3");
    pNtfData = pNtf->getReaderEventNotificationData();
    if(NULL == pNtfData)
    {
        goto fail;
    }

The output is -

2902Z-001/RFID/example# ./example1 -v 169.254.209.30 124 5 INFO: Connecting to 169.254.209.30.... 6 7 INFO: Connected, checking status.... 8 9 Hello from check Hello from check 2 Segmentation fault (core dumped)

So clearly there is some problem between "Hello check 2" and "Hello check 3"

Is this a case of possible buffer overflow ?

RicoRicochet
  • 2,249
  • 9
  • 28
  • 53
  • Nobody will be able to help you unless you show the code. – G.M. May 14 '19 at 10:38
  • It is not an issue with the code, I am pretty sure it is an issue with the running environment, since multiple OS are involved. Maybe something related to how characters/ spaces are treated in these two OSs in question. – RicoRicochet May 14 '19 at 10:40
  • the code without any edits runs perfectly on the second system (Ubuntu), but any edit - adding or removing any comment, hitting a blank space etc results in segfault during runtime. – RicoRicochet May 14 '19 at 10:45
  • Are you saying the code editor crashes? – Khouri Giordano May 14 '19 at 10:50
  • no editors are involved, I am editing the code in simple vim editor. after edits, I can save the code, make the code but "cannot" run the code. – RicoRicochet May 14 '19 at 10:54
  • Inspect the files with `hexdump`, maybe there is a difference. You should remove all the source code until you are lest with smallest reproducible example and then post the source code. Does a simple `int main() {}` cause seg fault too? – KamilCuk May 14 '19 at 10:57
  • ok, thanks for the suggestion, checking – RicoRicochet May 14 '19 at 10:58
  • @KamilCuk int main() runs perfectly. Even putting a print command works. Now it is becoming a total headstumper. – RicoRicochet May 14 '19 at 11:06
  • 5
    Just run your program under a debugger. You are probably suffering from undefined behavior somewhere and the crash when you change something is just a coincidence. – Botje May 14 '19 at 11:11
  • will try that.. – RicoRicochet May 14 '19 at 11:23
  • There is no code between the `printf`s check 2 and 3. But as there is not newline at the end of check 3 maybe that output is still buffered and not yet printed at the time where the crash occurs. You might want to add a newline or flush stdout . – Werner Henze May 15 '19 at 13:18

0 Answers0