C 5.00 and 5.10 Code Generation Problem on Call to Function

ID Number: Q29850

5.00 5.10 | 5.10

MS-DOS | OS/2

buglist5.00 buglist5.10 fixlist6.00

Summary:

The C version 5.00 and 5.10 compilers generate incorrect code for a

call to the function strcpy() in the following program when it is

compiled in small or medium model. When the compiler produces code for

the following call

strcpy(macronames[nrmacros],line);

the generated code pushes the value of macrobuffer + totalmac, instead

of pushing macronames[nrmacros].

Sample Code

-----------

#include <stdio.h>

#include <string.h>

int nrmacros=0;

char macrobuffer[800],*macronames[10];

int l;

void openfiles()

{

char line[128];

int totalmac;

char *macropointer = macrobuffer;

macropointer = macrobuffer + totalmac;

macronames[nrmacros] = macropointer;

totalmac += l-1;

if ( totalmac <= 800 )

strcpy(macronames[nrmacros],line);

}

More Information:

The generated code assumes the following:

macronames[nrmacros] = macropointer = macrobuffer + totalmac;

However, by the time the call to strcpy() is made, this equivalence is

no longer true because the value of the variable totalmac has changed.

You can work around the problem by making the call to strcpy() as

follows:

strcpy(macropointer,line);

Microsoft has confirmed this to be a problem in C versions 5.00 and

5.10. This problem was corrected in C version 6.00.