【发布时间】:2013-05-01 16:10:36
【问题描述】:
我无法在 ncurses 中创建简单的文件选择。以下代码失败,valgring 说“条件跳转或移动取决于 main.cpp:122 中的未初始化值”
// Create items
m_MenuItems = new ITEM * [ m_Files.size() + 1 ];
int i = 0;
for ( vector < CFile >::iterator it = m_Files.begin(); it != m_Files.end(); ++it, ++i ) {
/* m_MenuItems[i] = new_item((*it).pName->c_str(), (*it).pDesc->c_str()); */
m_MenuItems[i] = new_item("file", "size");
cout << "[" << i << "]: " << (*it).pName->c_str() << ", " << (*it).pDesc->c_str() << endl;
} m_MenuItems[++i] = NULL; // Item list has to be null terminated.
// Create menu
m_Menu = new_menu( (ITEM **)m_MenuItems ); // ! line 122
cout << "Success" << endl;
输出就是这样:
[0]: main.cpp, 6888
[1]: a.out, 106798
[2]: .., 4096
[3]: listdir.cpp, 701
[4]: menu.cpp, 1908
[5]: ., 4096
Segmentation fault (core dumped)
什么可能导致未启动的变量?
【问题讨论】:
-
new_item返回什么? -
项目 *new_item(const char *name, const char *description);加上它在错误时返回 NULL。
-
上面代码的第122行是哪一行?
-
@MichaelDorgan new_menu 行,如 cmets 中所述。
-
我认为@MichaelDorgan 找到了您的问题。
标签: c++ segmentation-fault ncurses