[Bug 842258] Re: ARM strchr fails to convert c to char

Dr. David Alan Gilbert 842258 at bugs.launchpad.net
Thu Sep 8 09:50:32 UTC 2011


** Branch linked: lp:~davidgil-uk/ubuntu/oneiric/eglibc/fix-842258

-- 
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:
  In Progress

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