C 6.0 _outtext() Can Produce Protection Violation Error

ID Number: Q64789

6.00

OS/2

buglist6.00 fixlist6.00a

Summary:

Under certain conditions, the C 6.0 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

sample code below illustrates the problem:

Microsoft has confirmed this to be a problem in C version 6.0. This

problem was corrected in C version 6.0a.

More Information:

The following are three methods of working around this problem in C

6.0:

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

-or-

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

global variable.

-or-

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.)

Sample Code

-----------

/* Compile options needed: /AL

*/

#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

}

Additional reference words: 6.00