[newlib,arm] Fix return value of strcmp
Greta Yorsh
greta.yorsh@arm.com
Mon Dec 3 14:06:00 GMT 2012
This patch fixes a correctness problem in the of implementation strcmp
routine for arm in newlib.
Current implementation of strcmp in certain cases incorrectly returns a
negative value instead of positive, because it does not handle overflow of
subtraction of two unsigned integers. For example, if the execution of
strcmp reaches label compute_return_value and
r1 is c1000000
r2 is 41000000
then the return value
r0 is 80000000
which is treated as a negative number (the most significant bit of r0 is
set). This is incorrect, because r1 > r2 and thus the return value must be
positive. The attached patch uses the carry flag to identify such cases and
return the correct value. The patch also adds new test cases.
No regression on qemu for arm-none-eabi.
Passes the relevant tests in testuite/newlib.string.
Thanks,
Greta
2012-11-29 Greta Yorsh <Greta.Yorsh@arm.com>
* libc/machine/arm/strcmp.S (compute_return_value): Fix return
value.
* testsuite/newlib.string/strcmp-1.c (main): Add new test cases.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: newlib-strcmp-fix-return.v4.patch.txt.txt
URL: <http://sourceware.org/pipermail/newlib/attachments/20121203/627cfae5/attachment.txt>
More information about the Newlib
mailing list