Microsoft KB Archive/321653

= FIX: Cl.exe throws a buffer overflow error in Visual C++ .NET =

Article ID: 321653

Article Last Modified on 1/6/2006

-

APPLIES TO


 * Microsoft Visual C++ 6.0 Service Pack 5
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q321653



SYMPTOMS
In Microsoft Visual C++ .NET, when you compile an application by using the C/C++ compiler (Cl.exe), you may receive the following error message:

---

Microsoft Visual C++ Runtime Library

---

Buffer overrun detected!

Program: ...es\Microsoft Visual Studio .NET\VC7\BIN\cl.exe

A buffer overrun has been detected which has corrupted the program's internal state. The program cannot safely continue execution and must now be terminated.

---

OK

---

In Visual C++ 6.0, you may receive a C1001 error message such as the following:

&quot;fatal error C1001: INTERNAL COMPILER ERROR

(compiler file 'msc1.cpp', line 1794)

Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information&quot;



CAUSE
The compiler overflows a buffer that is intended to hold a precompiled header file name and, because Cl.exe is compiled with the Buffer Security Check flag (/GS), the buffer overflow warning dialog box appears and the process ends.

In Visual C++ .NET, the error occurs when you compile with the Automatic Use of Precompiled Headers switch (/YX) and you have a TMP environment variable that has a string length greater than or equal to 52 characters (for example, C:\Documents and Settings\Username\Local Settings\Temp).

In Visual C++ 6.0, the error occurs when you compile with /YX and the TMP environment variable's length is greater than or equal to 55 characters.



RESOLUTION
Make sure that the string length of the TMP environment variable is less than 52 characters.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section. This bug was corrected in Microsoft Visual C++ .NET 2003.



Steps to reproduce the behavior
 Create a new folder in your system with a path name that is longer than 52 characters. For example, C:\Thisisalongfoldernamethisisalongfoldernamethisisalongfoldername Open a Command Prompt window. At the command prompt, type the following to set the TMP environment variable:

set TMP=C:\thisisalongfoldernamethisisalongfoldernamethisisalongfoldername  Verify that the previous command succeeded by typing the set command. TMP should have the entry that you set in the previous step.  Create a new .cpp file. In this file, paste the following sample code: // test.cpp using namespace std;
 * 1) include

void main {   cout << &quot;Hello world!&quot;; }                    Compile the .cpp file in the Command Prompt window where you set the TMP environment variable. Type the following command to compile the program:

cl /YX test.cpp

Note You may have to set the necessary environment variables before you run this command. To do this, run Vsvars32.bat, which is in \Program Files\Microsoft Visual Studio .NET\Common7\Tools.</li></ol>

<div class="references_section">