Re: Who could tell me why the error address isn't the same?



"Lee Tow" <fbjlt@xxxxxxxxxxxxx> wrote in message news:e%23ttv8$THHA.5060@xxxxxxxxxxxxxxxxxxxxxxx
Hello all:
Look:
char str[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void main()
{
char name[8];
strcpy(name,str);
}
I use vc6.0,and when I set active project configuration to Win32 Debug,and
then the error address is 0x504f4e4d,and I set active project configuration
to Win32 Release and the error address is 0x4c4b4a49,I want to know why
error addresses are different in the same codes?Thanks very much.

If you look carefully at those "addresses" you'll notice that they have the same pattern. They're comprised of the letters from original <str>. 0x504f4e4d is the substring "MNOP", and 0x4c4b4a49 is the substring "IJKL". What actually happened is that the strcpy was writing outside of the memory occupied by <name> (which is a bug), into the rest of the stack. One place in the stack is used to tell the function (main) where to return to when it's done, and this place was overwritten with "MNOP" and "IJKL". So when the <main> tries to "return", it actually tries to jump to memory location "MNOP", which is unaccessible (luckily for you, because you've found the bug).

The difference between Debug and Release is that Debug build puts some extra data on the stack to help you debug easily. Because of this extra data the rest of the stack in Debug build is spoiled with garbage by 4 byte offset (in regards to Release build).
.



Relevant Pages

  • Re: Who could tell me why the error address isnt the same?
    ... the stack is completely different. ... When a program is compiled in debug mode, it uses the debug heap, the debug libraries, and ... learn this is to study the output from compilers). ... I use vc6.0,and when I set active project configuration to Win32 Debug,and ...
    (microsoft.public.vc.mfc)
  • Re: Need Help Debugging
    ... you should use straight and plain ADPlus.VBS from the debugger package. ... debug info loaded, etc... ... does that avoid using the stack ?!? ... which is our custom CRITICAL_SECTION class. ...
    (microsoft.public.win32.programmer.kernel)
  • [PATCH] i386: get rid of the use of KPROBE_ENTRY / KPROBE_END
    ... * Debug traps and NMI can happen at the one SYSENTER instruction ... * that sets up the real kernel stack. ... * a debug fault, and the debug fault hasn't yet been able to ...
    (Linux-Kernel)
  • Re: Ecos, LwIP, PPP and GPRS
    ... the modem has an IP stack built in. ... FTP is the most important right now. ... >>while printing the messages over another serial port. ... >Can you modify the debug output to go to a memory buffer instead of the ...
    (comp.arch.embedded)
  • Re: Problem only in release version!
    ... Debug version may still have the problem, but the stack space is better ... memory or a buffer on the stack is not always caught. ... > Just to affirm Jochen's point, the Debug version initializes most ...
    (microsoft.public.dotnet.languages.vc)