[PATCH] Do not create invalid pointers in C code of string functions.

Torvald Riegel triegel@redhat.com
Fri Jul 3 18:54:00 GMT 2015


Some of the x86 string functions create pointers based on input strings
that may be outside of the input strings.  When this happens in C code,
the compiler can potentially detect this, leading to warnings in
application code when those string functions are inlined.  Perform those
operations in the assembly code instead of the C code to fix this.

The respective operations all substract 1; this patch may prevent the
compiler from doing that at compile time if the input strings have known
addresses.  I haven't measured performance, but I'd guess that it's in
the noise except perhaps for microbenchmarks with tiny or empty strings.

If someone wants to propose a better patch, please do so.  But do it
quick because this issue currently prevents x86 builds with a recent
GCC :)

Tested on i686-linux.

2015-07-03  Torvald Riegel  <triegel@redhat.com>

	* sysdeps/x86/bits/string.h (__memmove_g): Do not create invalid
	pointer in C code.
	(__strcat_c): Likewise.
	(__strcat_g): Likewise.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: string.patch
Type: text/x-patch
Size: 2132 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150703/ca3fd293/attachment.bin>


More information about the Libc-alpha mailing list