【发布时间】:2011-08-20 13:12:33
【问题描述】:
仅当我在“免费”(发布)中使用 WinDDK nmake 编译器构建时才会出现此错误,该编译器执行优化。我无法在“已检查”构建或使用 VS 编译中重现此问题。
这是我的代码中发生的事情的伪代码:
main()
{
//variable init and other code
fprintf(log, "pre nullValue: %lu\n", NULL); //printf added for debugging
otherFunc();
funcWithError(str1, str2, NULL);
fprintf(log, "post nullValue: %lu\n", NULL);
fprintf(log, "post2 nullValue: %lu, %lu, %lu\n", NULL, 0, NULL);
}
BOOL otherFunc()
{
//variable init and other code
callToDll();
//...doing stuff
libusb_usb_open(var1); //If I remove this line there is no problem!!
//...doing more stuff
}
BOOL funcWithError(char* s1, char* s2, FUNC_PTR fp)
{
fprintf(log, "inFunc nullValue: %lu, %lu\n", NULL, fp);
if(fp != NULL)
return FALSE; //This line is being executed erroneously!!
}
日志输出:
前空值:0
inFunc nullValue: 0, 251208
发布空值:251208
post2 nullValue: 251208, 251208, 251208
注意:每次程序运行时重复出现的数字(251208)都是不同的数字
只需更改一行即可修复/导致它。这是libusb usb_open 电话。
- 最终我的问题是弄清楚如何解决问题(我无法避免那个电话)
- 但只是在堆栈/内存管理级别上,怎么可能让 NULL 不为零并且将文字值 '0' 打印为非零?
让我知道其他信息可能会有所帮助...
【问题讨论】:
-
也许参数传递约定到 libusb_usb_open 有问题,这会导致一些堆栈损坏。这是 64 位应用程序吗?也许你应该使用 %llu 而不是 %lu。找出问题的最佳方法是在汇编程序中调试这部分代码并检查发生了什么。
-
是的,我正在尝试保存查看程序集,所以我想我会发布。它是在 x86 机器上为 x86 编译的,所以不是 64 位的。所以 %llu 什么都不做。
标签: c++ memory-management stack libusb