This is the mail archive of the gcc-bugs@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]

[Bug libfortran/50192] New: Wrong character comparision with wide strings


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50192

             Bug #: 50192
           Summary: Wrong character comparision with wide strings
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tkoenig@gcc.gnu.org
                CC: jvdelisle@gcc.gnu.org


ig25@linux-fd1f:~/Krempel/4> cat compare.f90
program main
  character(kind=4,len=2) :: c1, c2
  c1 = 4_' '
  c2 = 4_' '
  c1(1:1) = transfer(257, mold=c1)
  c2(1:1) = transfer(64, mold=c2)
  if (c1 < c2) print *,"strange..."
end program main
ig25@linux-fd1f:~/Krempel/4> gfortran compare.f90
ig25@linux-fd1f:~/Krempel/4> ./a.out
 strange...

The problem is in compare_string.  We use

int
compare_string (gfc_charlen_type len1, const CHARTYPE *s1,
                gfc_charlen_type len2, const CHARTYPE *s2)
{
  const UCHARTYPE *s;
  gfc_charlen_type len;
  int res;

  res = memcmp (s1, s2, ((len1 < len2) ? len1 : len2) * sizeof (CHARTYPE));

which works on big-endian, but not on little-endian, where the memcmp is used
to compare (bytewise) 0x01 0x01 0x00 0x00 vs. 0x40 0x00 0x00 0x00.


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