This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib,arm] Fix return value of strcmp


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.

Attachment: newlib-strcmp-fix-return.v4.patch.txt.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]