Microsoft KB Archive/106400

{|
 * width="100%"|

BUG: Incorrect Code from Intrinsic memset Routine

 * }

Q106400

1.00 1.50 WINDOWS kbtool kbbuglist --- The information in this article applies to: - The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 --- SYMPTOMS ======== The compiler generates incorrect code for the intrinsic form of memset in certain cases. CAUSE ===== The compiler generates incorrect code for memset if all of the following conditions are met: 1. You are using the /Oi option, /O2 option (which includes /Oi), or "#pragma intrinsic( memset )" to instruct the compiler to generate the intrinsic version of the function. 2. You are using the /G2 or /G3 options. 3. The character to set (second argument) in the memset call is greater than 15. 4. The number of characters (third argument) is a constant, and it is less than 9. RESOLUTION ========== To avoid the problem, use a variable instead of a constant for the number of characters (third argument), or eliminate one of the above conditions. See the comments in the sample code below. STATUS ====== Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available. This problem does not occur with Visual C++ 32-bit Edition. MORE INFORMATION ================ The following sample code can be used to demonstrate the problem. Sample Code --- /* Compile options needed: and */ #include #include void main( void ) { char ach[11] ; /* int n = 8; */ /* uncomment and use n below */ ach[10] = '\0'; memset( ach, 'A', 10 ); memset( ach, 'B', 8 ); /* to avoid problem use n, not constant 8 */ printf( ach ); if ( ach[7] != 'B' ) printf( "\nsecond memset failed" ); else printf( "\nsecond memset succeeded" ); } Additional reference words: 1.00 1.50 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CLIss

Keywords : kb16bitonly

Issue type : kbbug

Technology : kbVCsearch kbAudDeveloper kbCVCComp