如何结束一个指向0xCCCCCCCC的指针 [英] How to end up with a pointer to 0xCCCCCCCC

查看:357
本文介绍了如何结束一个指向0xCCCCCCCC的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理崩溃的程序有时尝试读取地址 0xCCCCCCCC 的数据。 Google(和StackOverflow)是我的朋友,我看到它是未初始化的堆栈变量的MSVC调试代码。为了理解问题来自哪里,我试图重现这种行为:问题是我不能这样做。



问题是:你有一个代码显示指针如何结束指向 0xCCCCCCCC



谢谢。

解决方案

使用 / GZ编译器开关 / RTCs开关。请确保 / Od开关也用于禁用任何优化。 / p>


s



启用堆栈框架运行时错误检查,如下所示: / p>


  • 将局部变量初始化为非零值。这有助于识别在调试模式下运行时不会出现的错误。与版本构建相比,由于在发布构建中对堆栈变量进行编译器优化,因此堆栈变量在调试构建中仍然为零的可能性更大。一旦程序使用其堆栈的一个区域,编译器永远不会将其复位为0。因此,使用相同堆栈区域的后续未初始化堆栈变量可以返回先前使用此堆栈存储器所剩余的值。


  • 检测溢出和局部变量(如数组)的欠载。 / RTC不会在访问由结构内的编译器填充引起的内存时检测到溢出。填充可以通过使用align(C ++),/ Zp(Struct Member Alignment)或pack来实现,或者如果你以一种需要编译器添加填充的方式来排序结构元素。


  • 堆栈指针验证,它检测堆栈指针损坏。堆栈指针损坏可能由调用约定不匹配引起。例如,使用函数指针,您可以在导出为__stdcall的DLL中调用函数,但是将该函数的指针声明为__cdecl。




The program I'm working on crashes sometimes trying to read data at the address 0xCCCCCCCC. Google (and StackOverflow) being my friends I saw that it's the MSVC debug code for uninitialized stack variable. To understand where the problem can come from, I tried to reproduce this behavior: problem is I haven't been able to do it.

Question is: have you a code snippet showing how a pointer can end pointing to 0xCCCCCCCC?

Thanks.

解决方案

Compile your code with the /GZ compiler switch or /RTCs switch. Make sure that /Od switch is also used to disable any optimizations.

s

Enables stack frame run-time error checking, as follows:

  • Initialization of local variables to a nonzero value. This helps identify bugs that do not appear when running in debug mode. There is a greater chance that stack variables will still be zero in a debug build compared to a release build because of compiler optimizations of stack variables in a release build. Once a program has used an area of its stack, it is never reset to 0 by the compiler. Therefore, subsequent, uninitialized stack variables that happen to use the same stack area can return values left over from the prior use of this stack memory.

  • Detection of overruns and underruns of local variables such as arrays. /RTCs will not detect overruns when accessing memory that results from compiler padding within a structure. Padding could occur by using align (C++), /Zp (Struct Member Alignment), or pack, or if you order structure elements in such a way as to require the compiler to add padding.

  • Stack pointer verification, which detects stack pointer corruption. Stack pointer corruption can be caused by a calling convention mismatch. For example, using a function pointer, you call a function in a DLL that is exported as __stdcall but you declare the pointer to the function as __cdecl.

这篇关于如何结束一个指向0xCCCCCCCC的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆