KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q64789: _outtext Can Produce Protection Violation Error

Article: Q64789
Product(s): See article
Version(s): 6.00
Operating System(s): OS/2
Keyword(s): ENDUSER | buglist6.00 | mspl13_c
Last Modified: 15-AUG-1990

Under certain conditions, the C 6.00 version of _outtext can produce a
protection violation. The error occurs when executing protected-mode
programs compiled under the large and compact memory models. The
following sample code illustrates the problem:

Sample Code:

/* Compile with any optimizations in large or compact model... */

#include <stdio.h>
#include <graph.h>
#include <conio.h>

char a1[10] = "boogie";
char a2[10];

void main(void)
{
   _outtext(a1);        // This _outtext works correctly
   a2[0] = 'a';
   a2[1] = 'b';         // Construct a null-terminated string
   a2[2] = '\0';
   _outtext(a2);        // Segmentation Violation occurs here
}

Three methods of working around this problem are listed below:

1. Initialize the string (that is, char a2[10] = "\0";).

2. Declare the string variable as a local variable rather than as a
   global variable.

3. Increase the number of elements in the character array. In the
   large memory model, arrays in the range of 649 to 5,000 bytes in
   size will work without problems. Arrays containing 643 to 5,000
   bytes will work when compiling under the compact memory model.
   (Arrays larger than 5,000 bytes may work also; however, this has
   not been tested.)

Microsoft has confirmed this to be a problem with C version 6.00. We
are researching this problem and will post new information here as it
becomes available.

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.

Copyright Microsoft Corporation 1986-2002.