i386 optimized string functions incorrectly treat size_t argument as ssize_t

Mike Frysinger vapier@gentoo.org
Thu Sep 1 01:22:00 GMT 2005


three of the i386 optimized asm functions (strncpy, strncat, strncmp) use the 
asm instruction 'js' to test the size_t __n argument.  since size_t is 
unsigned and js tests the sign bit, passing a value like (size_t)-1 will 
cause these functions to behave incorrectly.

for example, this simple test works with the C implementation, but fails with 
the asm version:
assert (strncmp("foo", "bar", (size_t)-1) != 0);

find attached a patch which should resolve the issue by utilizing 'jz' (plus a 
trick) instead of 'js'
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: glibc-i386-strn-funcs-unsigned.patch
Type: text/x-diff
Size: 1308 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20050901/58119f1b/attachment.bin>


More information about the Libc-alpha mailing list