内存中的程序布局(是否覆盖了我的静态指针?) [英] Program layout in memory (is anything overwriting my static pointer?)

查看:81
本文介绍了内存中的程序布局(是否覆盖了我的静态指针?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我已经完成了在我们的产品中整理崩溃的工作

我们有崩溃信息和事件的avi(

不可能匹配,但稍后更多......)(顺便说一下这是一个单独的
线程VC9 / win32应用程序)


错误的调用堆栈有效进行


void * myBuf;


void myFunc( )

{


if(myBuf)

{

(这里可能会发生一些事情)

用myBuf做一些事情..除了调试中的'NULL'
我有b $ b信息

}

我的问题是..堆中的任何东西都可以覆盖myBuf

NULL?

另一个可能性是另一个静态变量,比如一个固定大小的数组

我们在界外写作。


我的老板刚刚告诉我,我们正在使用名为Smartheap的内存管理器,

垃圾知道那是什么正在做..


有何评论?

Hi,

I''ve been given the job of sorting out a crash in our product for
which we have the crash information and an avi of the event (which
can''t possibly match but more of that later...) (btw this is a single
threaded VC9 / win32 app)

The call stack for the bug effectively goes

void* myBuf;

void myFunc()
{

if( myBuf )
{
(maybe some stuff happens here)
do something with myBuf.. except it''s NULL in the debug
information I have
}

My question is.. can anything in the heap have overwritten myBuf with
NULL?
Another possibilty is another static variable, say a fixed size array
where we''re writing outside the bounds.

My boss just told me we''re using a memory manager called Smartheap,
crap knows what that''s doing..

Any comments?

推荐答案

simonl写道:
simonl wrote:




我已经完成了整理产品崩溃的工作

我们有崩溃信息和事件的avi(

不可能匹配,但后来更多......)(顺便说一下这是一个单一的
线程VC9 / win32应用程序)


错误的调用堆栈有效地进行了


void * myBuf;


void myFunc()

{


if(myBuf)

{
Hi,

I''ve been given the job of sorting out a crash in our product for
which we have the crash information and an avi of the event (which
can''t possibly match but more of that later...) (btw this is a single
threaded VC9 / win32 app)

The call stack for the bug effectively goes

void* myBuf;

void myFunc()
{

if( myBuf )
{


}


我的问题是..堆中的任何东西都可以用
$ b覆盖myBuf $ b NULL?
}

My question is.. can anything in the heap have overwritten myBuf with
NULL?



一堆?如果您的应用程序是线程化的并且对myBuf的写入是无保护的,那么任何事情都可能发生。 myBuf不是静态的,它是全球的。


-

Ian Collins。

One the heap? If your application is threaded and writes to myBuf are
unguarded, anything might happen. myBuf isn''t static, its global.

--
Ian Collins.


simonl写道:
simonl wrote:




我已经完成了整理产品崩溃的工作

我们有崩溃信息和事件的avi

(这不可能匹配但后来更多......)(btw

这是一个单线程VC9 / win32应用程序)


错误的调用堆栈有效地进行了


void * myBuf ;


void myFunc()

{


if(myBuf)

{

(也许这里发生了一些事情)

用myBuf做一些事情..除了它在调试中是NULL

我有的信息

}


我的问题是..堆中的任何东西都可以被覆盖

myBuf是否为NULL?

另一个可能性是另一个静态变量,比如说修复ed size

数组我们在界外写作。


我的老板刚刚告诉我我们正在使用一个名为

Smartheap,废话知道那是做什么的。


有何评论?
Hi,

I''ve been given the job of sorting out a crash in our product
for which we have the crash information and an avi of the event
(which can''t possibly match but more of that later...) (btw
this is a single threaded VC9 / win32 app)

The call stack for the bug effectively goes

void* myBuf;

void myFunc()
{

if( myBuf )
{
(maybe some stuff happens here)
do something with myBuf.. except it''s NULL in the debug
information I have
}

My question is.. can anything in the heap have overwritten
myBuf with NULL?
Another possibilty is another static variable, say a fixed size
array where we''re writing outside the bounds.

My boss just told me we''re using a memory manager called
Smartheap, crap knows what that''s doing..

Any comments?



测试NULL!= myBuf(注意在C中你应该总是测试

明确地反对NULL宏,它可能被定义为不

在所有系统上的值为0,0xffffffff可能是常见的,

只是告诉你指针是否已被标记为无效/ NIL

明确地说。然而它并没有告诉你它是否有效。


你可能有一个完美的非NULL指针,它仍然没有

指向有效的内存。


最终你希望myBuf在没有初始化时为NULL。

(大)惊喜:变量不是初始化

明确可以获得任何值,直到获得一个值。


所以将这两个更改添加到您的程序中,看看它是否有效

然后:


- 无效* myBuf;

+ void * myBuf = NULL;


- if(myBuf)

+ if(NULL!= myBuf)


您可以尝试用调试器测试程序,设置一个手表
myBuf上的
,看看它何时发生变化。


Wolfgang Draxinger

-

电子邮件地址作品,Jabber: he******@jabber.org ,ICQ:134682867

Testing for NULL != myBuf (note in C you should always test
against the NULL macro explicitly, it may be defined as not
being of value 0 on all systems, 0xffffffff may be as common),
just tells you if the pointer has been marked invalid/NIL
explicitly. It doesn''t tell you however if it''s valid.

You may have a perfectly non-NULL pointer, that''s still not
pointing into valid memory.

Eventually you expect myBuf to be NULL if it''s not initialized.
(Big) surprise though: Variables not being initialized
explicitly can have any value until getting a value assigned.

So add these two changes to your program, and see if it works
then:

- void* myBuf;
+ void *myBuf = NULL;

- if( myBuf )
+ if( NULL != myBuf )

And you might try test your program with a debugger, set a watch
on myBuf, to see when it changes.

Wolfgang Draxinger
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867


Wolfgang Draxinger< wd * *******@darkstargames.dewrote:
Wolfgang Draxinger <wd********@darkstargames.dewrote:

测试NULL!= myBuf(在C中注意你应该总是测试

明确地反对NULL宏,它可能被定义为不是所有系统上的值为0的b $ b,0xffffffff可能是常见的,
Testing for NULL != myBuf (note in C you should always test
against the NULL macro explicitly, it may be defined as not
being of value 0 on all systems, 0xffffffff may be as common),



这是胡说八道。值为零的常量整数表达式

(例如,ooh,可能为0)将_always_ compare等于空指针,

,无论该空指针如何表示在记忆中;和一个布尔值

对任何标量的测试,包括指针,_always_就好像它被写为包含!= 0。


Richard

This is nonsense. A constant integer expression with the value zero
(such as, ooh, perhaps 0) will _always_ compare equal to a null pointer,
no matter how that null pointer is represented in memory; and a boolean
test against any scalar, including pointers, _always_ happens as if it
was written to include !=0.

Richard


这篇关于内存中的程序布局(是否覆盖了我的静态指针?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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