string_intrinsics.c (compare_string): Use memcmp instead of strncmp to avoid tripping...
authorThomas Koenig <Thomas.Koenig@online.de>
Sun, 28 May 2006 20:25:15 +0000 (20:25 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 28 May 2006 20:25:15 +0000 (20:25 +0000)
2006-05-28  Thomas Koenig  <Thomas.Koenig@online.de>

* intrinsics/string_intrinsics.c (compare_string):
Use memcmp instead of strncmp to avoid tripping over
CHAR(0) in a string.

2006-05-28  Thomas Koenig  <Thomas.Koenig@online.de>

* gfortran.dg/string_null_compare_1.f:  New test case.

From-SVN: r114175

gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/string_null_compare_1.f [new file with mode: 0644]
libgfortran/ChangeLog
libgfortran/intrinsics/string_intrinsics.c

index 786b6cae445c5159e2aac9bb1647cf6e5310b74d..96c5729e534148ab38dc1986a673496faf9df675 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-28  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       * intrinsics/string_intrinsics.c (compare_string):
+       Use memcmp instead of strncmp to avoid tripping over
+       CHAR(0) in a string.
+
 2006-05-27  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/27773
diff --git a/gcc/testsuite/gfortran.dg/string_null_compare_1.f b/gcc/testsuite/gfortran.dg/string_null_compare_1.f
new file mode 100644 (file)
index 0000000..2e6eb1b
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do run }
+! PR 27784 - Different strings should compare unequal even if they
+!            have CHAR(0) in them.
+
+      program main
+      character*3 str1, str2
+      call setval(str1, str2)
+      if (str1 == str2) call abort
+      end
+
+      subroutine setval(str1, str2)
+      character*3 str1, str2
+      str1 = 'a' // CHAR(0) // 'a'
+      str2 = 'a' // CHAR(0) // 'c'
+      end
index 4a31e484a2c15561c669b9032e6667a6dce43b9c..50ebaf230c06b4400adc82fc8f80d4a97769395e 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-28  Thomas Koenig  <Thomas.Koenig@online.de>
+
+       * intrinsics/string_intrinsics.c (compare_string):
+       Use memcmp instead of strncmp to avoid tripping over
+       CHAR(0) in a string.
+
 2006-05-27  Janne Blomqvist  <jb@gcc.gnu.org>
 
        * io/io.h (find_or_create_unit): Correct export declaration.
index eed41d71c8a088f3cca0432f9822dfeca596f80e..1bc4ff2201229315b39a6cbaf237ca73d1e55488 100644 (file)
@@ -109,7 +109,7 @@ compare_string (GFC_INTEGER_4 len1, const char * s1,
   const char *s;
   int len;
 
-  res = strncmp (s1, s2, (len1 < len2) ? len1 : len2);
+  res = memcmp (s1, s2, (len1 < len2) ? len1 : len2);
   if (res != 0)
     return res;