linux-mips
[Top] [All Lists]

bug in memscan()

To: linux-mips@oss.sgi.com
Subject: bug in memscan()
From: Machida Hiroyuki <machida@sm.sony.co.jp>
Date: Wed, 24 Oct 2001 18:27:44 +0900
Cc: takemura@sm.sony.co.jp, shin@sm.sony.co.jp
Sender: owner-linux-mips@oss.sgi.com
Hi, all.

We found a bug of memscan() in include/asm-mips/string.h.

Memscan() must compare a given 2nd parameter with memory by using 
unsinged char, as memchr() do. But, memscan() in
include/asm-mips/string.h and lib/string.c don't so. 

Please refer memchr() in sysdeps/generic/memchr.c of glic and 
lib/string.c.

I attached sample fixes.


Index: include/asm-mips/string.h
===================================================================
RCS file: /cvs/linux/include/asm-mips/string.h,v
retrieving revision 1.18
diff -u -p -r1.18 string.h
--- include/asm-mips/string.h   2001/10/06 19:29:25     1.18
+++ include/asm-mips/string.h   2001/10/24 09:17:05
@@ -142,11 +142,11 @@ extern __inline__ void *memscan(void *__
                ".set\treorder\n\t"
                "1:\tbeq\t%0,%1,2f\n\t"
                "addiu\t%0,1\n\t"
-               "lb\t$1,-1(%0)\n\t"
+               "lbu\t$1,-1(%0)\n\t"
                "bne\t$1,%z4,1b\n"
                "2:\t.set\tpop"
                : "=r" (__addr), "=r" (__end)
-               : "0" (__addr), "1" (__end), "Jr" (__c));
+               : "0" (__addr), "1" (__end), "Jr" ((unsigned char)__c));
 
        return __addr;
 }
Index: lib/string.c
===================================================================
RCS file: /cvs/linux/lib/string.c,v
retrieving revision 1.13
diff -u -p -r1.13 string.c
--- lib/string.c        2001/06/13 17:28:17     1.13
+++ lib/string.c        2001/10/24 09:17:05
@@ -477,7 +477,7 @@ void * memscan(void * addr, int c, size_
        unsigned char * e = p + size;
 
        while (p != e) {
-               if (*p == c)
+               if (*p == (unsigned char)c)
                        return (void *) p;
                p++;
        }
---
Hiroyuki Machida
Sony Corp.

<Prev in Thread] Current Thread [Next in Thread>