内存溢出 [英] Memory overrun

查看:63
本文介绍了内存溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何指尖规则技术可以发现内存溢出?
一旦知道内存溢出,是否有流程要通过?
由于有许多旨在在这种情况下提供帮助的软件,但是大多数情况下,它们只是指出您的进程崩溃的地方,到那时您可能已经知道了一些事情
我很高兴听到有人可以告诉我要检查的主要内容,或者可以采取哪些措施防止它如此频繁地发生,
谢谢.

Are there any fingure rules techniques for finding memory overrrun?
Is there a flow to go through once you know there is a memory overrun?
Since there are lots of softwares that are designed to be helpfull in these situation, but most of the time they just point out to you where your process crashes, something that you probably knew by that time
I will be happy to hear from someone who can tell me what are the main things to check, or what can you do to prevent it from happen so frequently
Thanks.

推荐答案

有一些工具,purif,边界检查器,但在我看来,它们倾向于为您提供很多信息. (也可能很贵)

确定崩溃点后,我将执行以下操作:

记下发生崩溃的地址,查看该地址处的内存,以查看是否提供了有关发生溢出的任何线索

然后,如果调试器将倒带回去,请在代码中向后移动,观察内存中是否有更改它的语句(变为红色).

有时,如果您重新启动应用程序并对其进行调试,它将与上次相同的地址,如果这样的话,您可以在遍历代码时在内存窗口中查看内存.

如果您不能执行上述操作,请在崩溃点之前注释掉代码,直到它停止崩溃为止,这将帮助您识别此技术在发布版本中也可以使用的原因行.

可以避免此问题的事情
始终使用mem copy functiosn允许指定大小限制
strncpy,例如memncpy.常见的原因是memcpy,strcat strcpy复制的字节多于缓冲区中的字节.

由于对指针的理解不足,例如
,我也看到了此问题
采用类似
There are some tools for this, purif, bounds checker but in my opinion they tend to present you with to much information. (Also they can be expensive)

This is what I would do once you have Identified the crash point:

Note the address at which the crash occurred, view the memory at this address looking to see if it give any clues as to where the overrun occured

Then work backward from that point, if your debugger will rewind move back in the code watching the memory for the statement that changes it (goes red).

Sometimes if you restart your application and debug it, it will be at the same address as last time, if so you can watch the memory in the memory window as you step through the code.

If you can''t do the above, comment out code before the crash point until it stops crashing this will help you identify the cause line(s) this techneque also works in release builds.

Things that help avoid this problem
always use the mem copy functiosn the allow a size limit to be specified
strncpy, memncpy for example. common causes are memcpy, strcat strcpy copying more bytes than in a buffer.

I''ve also seen this problem due to poor understanding of pointers e.g.

take a function definition like
void SetValue(int* pValToSet) { *pValToSet = 100; }


的函数定义
此函数只是将int设置为100,但有时会这样错误地调用它



This function just set an int to 100, but sometime it is called incorrectly like this

int* pIntToSet;
// this is going to overrite memory
SetValue(pIntToSet);


指针未设置为任何值,并且在释放模式下将包含随机数,该随机数可能是地址

应该是


The pointer is no set to anything and will contain a random number in release mode that may be an address

should be

int IntToSet = 0;
SetValue(&IntToSet);



其他提示:

始终初始化指向nullptr的指针
当处理字符串时,将内存设置为将字符串保持为0(空),例如



Other tips:

Always initialise pointers to nullptr
When dealing with strings set memory holding the string to 0 (null) e.g.

char myString[255];
memset(myString, 0, sizeof(myString));
// the string is now null terminated and ready to us
// also note myString[254] is the last element of this array not myString[255]



还有更多示例,但可惜我没有时间将其转为论文



There are many more examples, but sadly I don''t have time to turn this into an essay


///我很高兴听到有人可以告诉我主要内容要检查的事情,或者您可以采取哪些措施防止它如此频繁地发生

尝试为使用的数据对象创建自己的库
这将仅提供经过验证的内存访问:)
// I will be happy to hear from someone who can tell me what are the main things to check, or what can you do to prevent it from happen so frequently

Try to create your own library of the used data objects
which will provide the validated memory access only :)


这篇关于内存溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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