Intrinsic memcpy() in C 6.0 May Produce Incorrect Code

ID Number: Q64791

6.00 | 6.00

MS-DOS | OS/2

buglist6.00 fixlist6.00a

Summary:

The Microsoft C Compiler version 6.0 may produce incorrect code in

rare cases when the intrinsic form of memcpy is used in large (/AL)

memory model.

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 sample code below illustrates this problem. If the code is

compiled for large (/AL) memory model with optimization that includes

intrinsic functions (/Oi, /Ox, /Oz), the machine will hang under DOS

or a protection violation will be generated under OS/2.

To work around this problem, either compile without the /Oi option or

use #pragma "function(memcpy)" to specify the use of the function form

of memcpy(). The pragma may be turned off for functions following it

by using #pragma intrinsic(memcpy) to go back to the intrinsic form of

memcpy.

Sample Code

-----------

/* Compile options needed: /AL /Oi

*/

#include <stdio.h>

#include <string.h>

#include <malloc.h>

typedef struct

{

int dummy;

char *f_char[8];

char *f_attr[8];

} t_field;

void copy_fieldtxt(t_field *, t_field *, int, int);

void main(void)

{

t_field *src, *dst;

void *calloc();

src=(t_field *)calloc(1,sizeof(t_field));

dst=(t_field *)calloc(1,sizeof(t_field));

src->f_char[0]= strdup("Text string");

src->f_attr[0]= strdup("attribute string");

dst->f_char[1]=strdup("Text string");

dst->f_attr[1]=strdup("attribute string");

copy_fieldtxt(src,dst,0,1);

printf("dst->attr[1]==>%s\n",dst->f_attr[1]);

}

/* Copies src->f_char[srcndx] to dst->f_char[dstndx]

and src->f_attr[srcndx] to dst->f_attr[dstndx] */

void copy_fieldtxt(t_field *src, t_field *dst, int srcndx, int dstndx)

{

int maxlen=strlen(dst->f_attr[dstndx]);

memcpy(dst->f_char[dstndx], src->f_char[srcndx], maxlen);

memcpy(dst->f_attr[dstndx], src->f_attr[srcndx],maxlen);

}