0

我在 CentOS 7 系统(64 位)上使用 LLRP API 编写了一段 C++ 代码来连接 RFID 阅读器,它一直运行良好。我把那个 .cpp 文件复制到我的 Ubuntu 14.04 桌面(也是 64 位),然后“make”-ing 文件成功运行。

当我尝试编辑 .cpp 文件时出现问题。即使插入或删除单个字符/空格/注释也会导致“分段错误(核心转储)”。

.cpp 文件可以在编辑后通过“make”成功保存和编译,但是在使用 ./ 运行可执行文件时出现分段错误。

我只使用简单的 gedit 和 vim。我猜这个问题与两个操作系统如何处理文本字符有关。有什么线索吗?

更多观察---

根据建议,我尝试删除所有代码并保留 -

int main()
{
}

并且代码运行成功。那么现在可能是什么问题?

* 更多细节 *

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

输出是 -

2902Z-001/RFID/example# ./example1 -v 169.254.209.30 124 5 信息:连接到 169.254.209.30.... 6 7 信息:已连接,正在检查状态.... 8 9 Hello from check 来自 check 2分段错误(核心转储)

很明显,“Hello check 2”和“Hello check 3”之间存在一些问题

这是可能的缓冲区溢出的情况吗?

4

0 回答 0