BUG: Intrinsic Version of strlen() Fails

Last reviewed: July 22, 1997
Article ID: Q115325
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbtool kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
    

SYMPTOMS

The intrinsic version of the strlen() function fails for arrays larger than 65535 bytes. The compiler options needed to reproduce the problem are /Oi and /AL, as shown with the sample code in the "MORE INFORMATION" section of this article.

RESOLUTION

The problem can be worked around using one of the following methods:

  • Compile without /Oi.

    -or-

  • Compile with /Od.

    -or-

  • Compile with /f- in Visual C++, versions 1.0, 1.50, or 1.50.01.

    -or-

  • Use #pragma function(strlen).

    -or-

  • Use #pragma optimize("", off) in Visual C/C++ 1.0, 1.50, or 1.50.01.

STATUS

Microsoft has confirmed this to be a bug in the products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This is not a problem in Visual C++ 1.0, 32-bit Edition.

MORE INFORMATION

The following code can be used to demonstrate this problem:

Sample Code

/* Compile options needed: /Oi /AL
*/

#include <string.h>
#include <stdio.h>

// #pragma function(strlen) // This line needed to fix the problem

char _far sz65535[65536];

void main(void)
{
   size_t length;

   memset(sz65535, 'A', 65535U);
   sz65535[65535] = '\0';
   length = strlen( sz65535);

   printf( "Actual Length of string is 65535,\n"
           "strlen(sz65535) returned %u\n", length);
}

REFERENCE

More information on #pragma can be found in the online Help for Visual C++ or by typing "qh #pragma" at the MS-DOS prompt in C/C++, version 7.0.


Additional reference words: 1.00 1.50 7.00 8.00 8.00c
KBCategory: kbtool kbbuglist
KBSubcategory: CLIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.