[Bug 842258] [NEW] ARM strchr fails to convert c to char
Colin Watson
cjwatson at canonical.com
Tue Sep 6 00:49:36 UTC 2011
Public bug reported:
C99 says:
"The strchr function locates the first occurrence of c (converted to a
char) in the string pointed to by s."
The current ARM strchr implementation in eglibc (2.13-17ubuntu2) starts
off like this:
ldrb r2,[r0],#1
cmp r2,r1
This loads a byte from the address pointed to by the first argument (s),
zero-extends it to 32 bits, and then compares it directly against the
second argument (c). If c is negative, this fails.
I think that this function should first convert c to a char, e.g. by
zeroing the top 24 bits. char is unsigned on this platform, so (char)
-1 == (int) 255.
Here's a test program. By my reading of C99, it should return 0. On
Ubuntu 11.10 armel, it currently returns 1. (This is the root cause of
bug 791274, although it's easily worked around by passing the anyway
less obtuse value of 255 rather than -1.)
#include <string.h>
int main(int argc, char **argv) {
const char *s = "\xff";
if (strchr (s, -1) == s)
return 0;
else
return 1;
}
** Affects: eglibc (Ubuntu)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to eglibc in Ubuntu.
https://bugs.launchpad.net/bugs/842258
Title:
ARM strchr fails to convert c to char
Status in “eglibc” package in Ubuntu:
New
Bug description:
C99 says:
"The strchr function locates the first occurrence of c (converted to
a char) in the string pointed to by s."
The current ARM strchr implementation in eglibc (2.13-17ubuntu2)
starts off like this:
ldrb r2,[r0],#1
cmp r2,r1
This loads a byte from the address pointed to by the first argument
(s), zero-extends it to 32 bits, and then compares it directly against
the second argument (c). If c is negative, this fails.
I think that this function should first convert c to a char, e.g. by
zeroing the top 24 bits. char is unsigned on this platform, so (char)
-1 == (int) 255.
Here's a test program. By my reading of C99, it should return 0. On
Ubuntu 11.10 armel, it currently returns 1. (This is the root cause
of bug 791274, although it's easily worked around by passing the
anyway less obtuse value of 255 rather than -1.)
#include <string.h>
int main(int argc, char **argv) {
const char *s = "\xff";
if (strchr (s, -1) == s)
return 0;
else
return 1;
}
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/842258/+subscriptions
More information about the foundations-bugs
mailing list