Re: Re:_[CPP]几道C语言的题

Siney siney at yeah.net
Thu Jan 18 11:00:40 CST 2007


Xu Ziding,您好!

	你这种情况是系统的堆栈上溢出吧,其实就单那一行也没有问题,下溢是指堆栈用光了,比如递归太深,或者分配了一个很大的buffer。

	上溢的情况:

	void foo()
	{
		char buf[2];
		sprintf(buf,"hello world"); //超过buf的容量
	}

	下溢的情况:
	void foo()
	{
		char buf[1000];
		foo(); //死循环的递归
	}

	上溢会导致破坏上层堆栈数据,或者修改了堆栈返回地址,导致错误的eip;
	下溢会导致访问非法数据,导致crash。

	上面是我的个人理解,请各位指正。

======= 2007-01-18 09:19:20 您在来信中写道:=======

>试试这个
>void fun(int a)
>{
> __asm{
>pop eax
>}
>}
>2007/1/18, 孙华明 <sunhm at neusoft.com>:
>> 题目没有明确说是指容器堆栈,还是操作系统的栈。
>> 不过感觉不应该是指操作系统的栈,操作系统的栈应该是有操作系统负责的吧。
>> 应该是容器堆栈。
>
>
>_______________________________________________
>Cpp mailing list
>Cpp at codingnow.com
>http://codingnow.com/mailman/listinfo/cpp

= = = = = = = = = = = = = = = = = = = =
			

        致
礼!
 
				 
        Siney
        siney at yeah.net
          2007-01-18




More information about the Cpp mailing list