这些 valgrind/GNU 调试器错误消息是什么意思
What do these valgrind/GNU debugger error messages mean?
我的程序正确终止,根据Valgrind的说法,没有泄漏的内存。
但是,首次运行对象方法时,会出现以下消息。
Use of uninitialised value of size 8
获取有关上述内容的更多详细信息
==18787== Use of uninitialised value of size 8
==18787== at 0x4017F3: Grid::init(int) (grid.cc:90)
==18787== by 0x401D2A: main (main.cc:43)
==18787== Uninitialised value was created by a stack allocation
==18787== at 0x401BE4: main (main.cc:11)
我还看到以下消息:
Conditional jump or move depends on uninitialised value(s)
Invalid free() / delete / delete[] / realloc()
Address 0x7ff000b08 is on thread 1's stack
这是网格的代码::init
void Grid::init(int n){
if (!(&(this->theGrid))) { this->clearGrid(); } //If non-empty, destroys grid
this->theGrid = new Cell*[n]; //Create new grid of size n x n
this->td = new TextDisplay(n); //new Text Display
for (int i = 0; i < n; i++){
this->theGrid[i] = new Cell[n];
for(int j = 0; j < n; j++){ //Cell initializations
(this->theGrid[i][j]).setDisplay(this->td); //set display
(this->theGrid[i][j]).setCoords(i, j); //set co-ordinates
(this->theGrid[i][j]).setState(0); //default state
}
}
}
我猜你的代码看起来像:
条件跳转或移动取决于未初始化的值:
bool value /* nothing */;
if (value) {
}
无效免费:
char* buf = new char[10000];
buf = &x;
delete [] buf;
现在你发布了代码,我假设第 90 行是这个:
if (!(&(this->theGrid))) { this->clearGrid(); } //If non-empty, destroys grid
问题是你没有初始化theGrid
以在构造函数中nullptr
,然后你最终可能会delete[]
一个非new[]
-ed 数组。此外,如果您只是这样做,该代码将读起来更干净:
if (!theGrid) {
clearGrid();
}
您不需要到处this->
。我不明白你为什么要拿theGrid
的地址.
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 收到消息时,lParam 的行为是什么WM_KEYDOWN?
- 给定哈希函数解码消息的最佳方法是什么
- 我不确定这些错误消息是什么意思
- 服务器进程等待客户端输入/消息的最佳方法是什么?
- gcc 的自动矢量化消息是什么意思?
- cimg display()什么都没有,但调试消息是正确的
- "first-chance exception..."消息中的十六进制数字是什么意思?
- 在 protobuf 中处理可选消息的正确方法是什么
- 使用 C++/WinAPI 在对话窗口中释放资源的相应消息是什么?
- 这些 valgrind/GNU 调试器错误消息是什么意思
- 在 c++ 中使用消息结构读取/填充数据缓冲区的正确方法是什么?
- 通过流分析不完整的 XML 消息的最有效方法是什么?
- 您在软件中编写日志以处理可能大量的日志消息的策略是什么
- C和C++编译器为下面的代码给出了不同的消息,原因是什么
- 在c++中包含错误消息的首选方式是什么?
- 是什么导致删除函数错误消息
- 在控制台应用程序中包含"help"消息的最佳方法是什么?
- visual studio中错误信息后面的消息是什么意思?
- 对于常量大小的protobuf消息,什么是好的实践?