This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, libfortran] Fix PR 30525 - character comparisons with padding


Thomas Koenig wrote:
Hi world,

here is a simple fix for PR 30525.  Regression-tested on
i686-pc-linux-gnu.

OK for mainline and (after a suitable delay) for 4.2?

Thomas

2007-01-21 Thomas Koenig <Thomas.Koenig@online.de>

	* intrinsics/string_intrinsics.c(compare_string):  Make
	sure that comparisons are done unsigned.

2007-01-21 Thomas Koenig <Thomas.Koenig@online.de>

* gfortran.dg/char_comparison_1.f: New test.



------------------------------------------------------------------------

Index: intrinsics/string_intrinsics.c
===================================================================
--- intrinsics/string_intrinsics.c (revision 120646)
+++ intrinsics/string_intrinsics.c (working copy)
@@ -83,7 +83,7 @@ compare_string (GFC_INTEGER_4 len1, cons
GFC_INTEGER_4 len2, const char * s2)
{
int res;
- const char *s;
+ const unsigned char *s;
int len;
res = memcmp (s1, s2, (len1 < len2) ? len1 : len2);
@@ -96,13 +96,13 @@ compare_string (GFC_INTEGER_4 len1, cons
if (len1 < len2)
{
len = len2 - len1;
- s = &s2[len1];
+ s = (unsigned char *) &s2[len1];
res = -1;
}
else
{
len = len1 - len2;
- s = &s1[len2];
+ s = (unsigned char *) &s1[len2];
res = 1;
}



------------------------------------------------------------------------


C { dg-do run }
C     PR 30525 - comparisons with padded spaces were done
C     signed.
      program main
      character*2 c2
      character*1 c1, c3, c4
C
C  Comparison between char(255) and space padding
C
      c2 = 'a' // char(255)
      c1 = 'a'
      if (.not. (c2 .gt. c1)) call abort
C
C  Comparison between char(255) and space
C
      c3 = ' '
      c4 = char(255)
      if (.not. (c4 .gt. c3)) call abort

C
C  Check constant folding
C
      if (.not. ('a' // char(255) .gt. 'a')) call abort

      if (.not. (char(255) .gt. 'a')) call abort
      end
This looks OK and obvious. I am bootstrapping now and will test.

Jerry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]