0

我正在尝试使用 fseek 查找文件的末尾,一次以 2560 * 5 个字节的步长查找。不知道为什么会出现分段错误,我在 TDA2x 板上运行此代码。这是我不知道的特定环境中的问题吗?

uNumFrames 的起始值为 1000 这段代码基本上是尝试从外部连接的 SSD 驱动器读取数据,并且正在逐字节读取文件,使用 fseek 跳过文件中的某些容器。我面临的问题是,在尝试读取这样的文件时,代码因以下详细信息而崩溃

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--;
}

示例输出如下所示:

[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:
4

0 回答 0