Microsoft KB Archive/318669

= BUG: Local Variables Are Overwritten When You Use /ZI and /Od Compiler Switches =

Article ID: 318669

Article Last Modified on 7/23/2002

-

APPLIES TO


 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q318669



SYMPTOMS
When you use the /ZI (Program Database for Edit & Continue) and /Od (Disable Optimizations) compiler switches, local variables may be overwritten.



RESOLUTION
To work around this problem, use one of the following methods:
 * Use the /Zi (Program Database) switch instead of the /ZI (Program Database for Edit & Continue) switch.
 * Use the /RTC1 (Basic Runtime Checks) switch, which is equivalent to the /RTCsu switch.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
Although space for all of the local variables is allocated on the stack, some variables may be assigned an address in a local array instead of in the space that is already allocated on the stack. Therefore, if you fill the array, one or more of the local variables may be overwritten even though the return address for the function remains intact.

The following sample code demonstrates the problem:
 * 1) include
 * 2) include

using namespace std;

int main {   const std::string& test = &quot;Some string&quot;; // Creates a temporary string. cout << &quot;'&quot; << test << &quot;'&quot; << endl;

{       char buf[100] = { 0 }; // ERROR: Overwrites the temporary string. cout << &quot;'&quot; << test << &quot;'&quot; << endl; }   return 0; } Use the /Od, the EHsc, and the ZI compiler switches to compile this sample.

Additional query words: reference variable

Keywords: kbbug kbfix kbcodegen kbcompiler KB318669

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.