? "\0abc" : "\0xyz"

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Wed Dec 22 16:31:00 GMT 1999


> The following code produces incorrect results under gcc 2.8.1, incorrect
> results under egcs 2.91.66, correct results under gcc 2.7.2.3, and
> _presumably_ (see below) incorrect results under the latest gcc:

Thanks for your bug report. I believe you are right, here is a patch.

The testsuite is running right now. Is it ok for the mainline, too?

Regards,
Martin

1999-12-23  Martin v. Löwis  <loewis@informatik.hu-berlin.de>

	* fold-const.c (operand_equal_p): Use memcmp to compare string
	constants.
	Suggested by D. J. Bernstein

char* doit(int flag)
{
  return 1 + (flag ? "\0wrong\n" : "\0right\n");
}
int main()
{
  char *result = doit(0);
  if (*result == 'r' && result[1] == 'i')
    exit(0);
  abort();
}

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fold-const.c,v
retrieving revision 1.93
diff -u -r1.93 fold-const.c
--- fold-const.c	1999/12/21 06:02:59	1.93
+++ fold-const.c	1999/12/23 00:08:27
@@ -2250,7 +2250,7 @@
 
       case STRING_CST:
 	return (TREE_STRING_LENGTH (arg0) == TREE_STRING_LENGTH (arg1)
-		&& ! strncmp (TREE_STRING_POINTER (arg0),
+		&& ! memcmp (TREE_STRING_POINTER (arg0),
 			      TREE_STRING_POINTER (arg1),
 			      TREE_STRING_LENGTH (arg0)));
 




More information about the Gcc-patches mailing list