0

I am trying to seek till the end of a file using fseek, seeking in steps of 2560 * 5 bytes at a time. No idea why I am getting a segmentation fault I am running this code on TDA2x board. Is here a problem in the particular environment which I am unaware of?

Starting value of uNumFrames is 1000 This code is basically trying to read the data from an externally connected SSD drive, and is reading the file byte by byte, skipping certain containers in the file using fseek. The problem I am facing is that while trying to read the files like this, the code is crashing with the following details

while(uNumFrames > 500)
{
    logger::addLog(logger::LOGGER_INFO,"Inside while loop, uNumFrames = %d", uNumFrames);
    /*Skip packet Header*/
    ui_skip_count = fseek(fp, HeaderSize * 5, SEEK_CUR);  
    fsize = ftell(fp);
    logger::addLog(logger::LOGGER_INFO,"fsize = %ld\n", fsize);

    if (ferror(fp))
    {
        logger::addLog(logger::LOGGER_INFO,"fseek Error");
        fclose (fp);
        break;
    }

    if(0 != ui_skip_count)
    {
        logger::addLog(logger::LOGGER_INFO,"fseek for fp failed");
    }
    else
    {
        logger::addLog(logger::LOGGER_INFO,"Inside else for read and scale");
    }
    uNumFrames--;
}

Sample output looks something like this:

[HOST  ] [INFO]    86.234680 s: Inside while loop, uNumFrames = 978
[HOST  ] [INFO]    86.234680 s: fsize = 3368961
[HOST  ] [INFO]    86.234710 s: Inside else for read and scale
[HOST  ] [INFO]    86.234710 s: Inside while loop, uNumFrames = 977
[HOST  ] [INFO]    86.234710 s: fsize = 3381761
[HOST  ] [INFO]    86.234710 s: Inside else for read and scale
[HOST  ] [INFO]    86.234710 s: Inside while loop, uNumFrames = 976
[HOST  ] [INFO]    86.234741 s: fsize = 3394561
[HOST  ] [INFO]    86.234741 s: Inside else for read and scale
[HOST  ] [INFO]    86.234741 s: Inside while loop, uNumFrames = 975
[HOST  ] [INFO]    86.234741 s: fsize = 3407361
[HOST  ] [INFO]    86.234741 s: Inside else for read and scale
[HOST  ] [INFO]    86.234741 s: Inside while loop, uNumFrames = 974
[HOST  ] [INFO]    86.234771 s: fsize = 3420161
[HOST  ] [INFO]    86.234771 s: Inside else for read and scale
[HOST  ] [INFO]    86.234771 s: Inside while loop, uNumFrames = 973
[HOST  ] [INFO]    86.234771 s: fsize = 3432961
[HOST  ] [INFO]    86.234771 s: Inside else for read and scale
[HOST  ] [INFO]    86.234771 s: Inside while loop, uNumFrames = 972
[HOST  ] [INFO]    86.234802 s: fsize = 3445761
[HOST  ] [INFO]    86.234802 s: Inside else for read and scale
[HOST  ] [INFO]    86.234802 s: Inside while loop, uNumFrames = 971
[HOST  ] [INFO]    86.234802 s: fsize = 3458561
[HOST  ] [INFO]    86.234802 s: Inside else for read and scale

****** Segmentation fault caught ....

Faulty address is 0xa6499020, called from 0x77ddb
Totally Obtained 0 stack frames. signal number =11 
 Signal number = 11, Signal errno = 0
 SI code = 1 (Address not mapped to object)
 Fault addr = 0xa6499020 
[bt] Execution path:
Backs
  • 24,430
  • 5
  • 58
  • 85
Sushant
  • 151
  • 1
  • 7
  • No error message, no exact line that the error occurs on, no input data. This is an incomplete question, voting to close – Vorsprung Nov 02 '15 at 10:40
  • `fseek()` is returning non-zero. Try to print the `errno` and/or `strerror(errno)`. It will contain the reason that caused `fseek()` to fail. – alvits Nov 03 '15 at 03:38
  • When checking for an error, you must do so immediately after the call you're testing. Not two or three calls later. – user207421 Nov 05 '15 at 03:41

0 Answers0