ARM strchr fails to convert c to char
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
eglibc (Ubuntu) |
Fix Released
|
Undecided
|
Dr. David Alan Gilbert |
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)
else
}
Related branches
- Colin Watson (community): Approve
-
Diff: 44 lines (+11/-1)2 files modifieddebian/changelog (+6/-0)
debian/patches/arm/local-linaro-cortex-strings.diff (+5/-1)
Changed in eglibc (Ubuntu): | |
assignee: | nobody → Dr. David Alan Gilbert (davidgil-uk) |
Hi Colin, /code.launchpad .net/~davidgil- uk/ubuntu/ oneiric/ eglibc/ fix-842258
Thanks for that (very clear) report - I've just created a branch that appears to do the trick:
https:/
and added you as a reviewer on it.
Dave