about summary refs log tree commit diff
path: root/termios
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2017-01-11 13:57:59 +0000
committerJoseph Myers <joseph@codesourcery.com>2017-01-11 13:57:59 +0000
commit38d01bd6df937f69c881df61b111492e941f2b74 (patch)
treeb68a63b80391325332212447183828abc76dddf6 /termios
parent64235ccc11175e6d4186a8fa911816cd7674d453 (diff)
downloadglibc-38d01bd6df937f69c881df61b111492e941f2b74.tar.gz
glibc-38d01bd6df937f69c881df61b111492e941f2b74.tar.xz
glibc-38d01bd6df937f69c881df61b111492e941f2b74.zip
Fix elf/sotruss-lib format-truncation error.
Building 64-bit glibc with GCC mainline fails with:

../elf/sotruss-lib.c: In function 'la_version':
../elf/sotruss-lib.c:91:28: error: '%lu' directive output may be truncated writing between 1 and 20 bytes into a region of size 11 [-Werror=format-truncation=]
      snprintf (endp, 12, ".%lu", (unsigned long int) pid);
                            ^~~
../elf/sotruss-lib.c:91:26: note: using the range [1, 18446744073709551615] for directive argument
      snprintf (endp, 12, ".%lu", (unsigned long int) pid);
                          ^~~~~~
../elf/sotruss-lib.c:91:6: note: format output between 3 and 22 bytes into a destination of size 12
      snprintf (endp, 12, ".%lu", (unsigned long int) pid);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Pids from getpid cannot actually be negative, but the compiler doesn't
know this.  Other places in this file use (signed) long int for
printing, so this patch makes this place do so as well.  Then it
increases the buffer size by one byte to allow for the minus sign that
can't actually occur.  It doesn't seem worth using diagnostic pragmas
to save one byte; other place in this file just use a cruder 3 *
sizeof (pid_t) calculation for number of digits.

Tested with GCC mainline with compilation for aarch64 with
build-many-glibcs.py, and with glibc testsuite for x86_64 (built with
GCC 6).

	* elf/sotruss-lib.c (init): Increase space allocated for pid by
	one byte.  Print it with %ld, cast to long int.
Diffstat (limited to 'termios')
0 files changed, 0 insertions, 0 deletions