This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

Fix memrchr


The first memrchr testcase in string/inl-tester failed for me with GCC
3.4.  Looking closer into it, Honza noticed that it is not valid C,
the arithmetic is wrong.

The appended patch fixes the bug.  Ok to commit?

Andreas

2003-01-06  Andreas Jaeger  <aj@suse.de>, Jan Hubicka <jh@suse.cz>

	* sysdeps/i386/i486/bits/string.h (__memrchr): Fix arithmetic.
	* sysdeps/i386/bits/string.h (__memrchr): Likewise.

============================================================
Index: sysdeps/i386/i486/bits/string.h
--- sysdeps/i386/i486/bits/string.h	4 Dec 2002 12:27:43 -0000	1.51
+++ sysdeps/i386/i486/bits/string.h	6 Jan 2003 15:10:00 -0000
@@ -1,5 +1,5 @@
 /* Optimized, inlined string functions.  i486 version.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -472,7 +472,7 @@ __memrchr (__const void *__s, int __c, s
 # ifdef __i686__
   register unsigned long int __d1;
 # endif
-  register void *__res;
+  register int __res;
   if (__n == 0)
     return NULL;
 # ifdef __i686__
@@ -497,7 +497,7 @@ __memrchr (__const void *__s, int __c, s
        "m" ( *(struct { __extension__ char __x[__n]; } *)__s)
      : "cc");
 # endif
-  return __res + 1;
+  return (void *)(__res + 1);
 }
 # ifdef __USE_GNU
 #  define memrchr(s, c, n) __memrchr (s, c, n)
============================================================
Index: sysdeps/i386/bits/string.h
--- sysdeps/i386/bits/string.h	6 Jul 2001 04:55:53 -0000	1.21
+++ sysdeps/i386/bits/string.h	6 Jan 2003 15:10:00 -0000
@@ -1,5 +1,5 @@
 /* Optimized, inlined string functions.  i386 version.
-   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -313,7 +313,7 @@ __STRING_INLINE void *
 __memrchr (__const void *__s, int __c, size_t __n)
 {
   register unsigned long int __d0;
-  register void *__res;
+  register int __res;
   if (__n == 0)
     return NULL;
   __asm__ __volatile__
@@ -325,7 +325,7 @@ __memrchr (__const void *__s, int __c, s
      : "=D" (__res), "=&c" (__d0)
      : "a" (__c), "0" (__s + __n - 1), "1" (__n)
      : "cc");
-  return __res + 1;
+  return (void *) (__res + 1);
 }
 # ifdef __USE_GNU
 #  define memrchr(s, c, n) __memrchr (s, c, n)


-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj


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