GNU Binutils with patches for OS216
Revisión | 97e64e5ab19dbf6a9babd711e8deec5545520954 (tree) |
---|---|
Tiempo | 2016-09-24 01:27:26 |
Autor | Yao Qi <yao.qi@lina...> |
Commiter | Yao Qi |
Replace sprintf with xsnprintf in nat/linux-osdata.c
I see the following build warning when I build GDB with GCC trunk.
../../binutils-gdb/gdb/nat/linux-osdata.c: In function ‘LONGEST linux_xfer_osdata_fds(gdb_byte*, ULONGEST, ULONGEST)’:
../../binutils-gdb/gdb/nat/linux-osdata.c:767:1: error: ‘%s’ directive writing between 0 and 255 bytes into a region of size 11 [-Werror=format-length=]
../../binutils-gdb/gdb/nat/linux-osdata.c:800:51: note: format output between 7 and 262 bytes into a destination of size 17
../../binutils-gdb/gdb/nat/linux-osdata.c: In function ‘LONGEST linux_xfer_osdata_threads(gdb_byte*, ULONGEST, ULONGEST)’:
../../binutils-gdb/gdb/nat/linux-osdata.c:555:1: error: ‘%s’ directive writing between 0 and 255 bytes into a region of size 11 [-Werror=format-length=]
../../binutils-gdb/gdb/nat/linux-osdata.c:588:51: note: format output between 7 and 262 bytes into a destination of size 17
cc1plus: all warnings being treated as errors
The warning is a false positive, but we can workaround it by replacing
sprintf with xsnprintf. On the other hand, it is always preferred to
use xsnprintf.
gdb:
2016-09-23 Yao Qi <yao.qi@linaro.org>
* nat/linux-osdata.c (linux_xfer_osdata_threads): Replace
sprintf with xsnprintf.
(linux_xfer_osdata_fds): Likewise.
@@ -1,3 +1,9 @@ | ||
1 | +2016-09-23 Yao Qi <yao.qi@linaro.org> | |
2 | + | |
3 | + * nat/linux-osdata.c (linux_xfer_osdata_threads): Replace | |
4 | + sprintf with xsnprintf. | |
5 | + (linux_xfer_osdata_fds): Likewise. | |
6 | + | |
1 | 7 | 2016-09-23 Pedro Alves <palves@redhat.com> |
2 | 8 | |
3 | 9 | * Makefile.in (SFILES): Add common/new-op.c. |
@@ -585,7 +585,8 @@ linux_xfer_osdata_threads (gdb_byte *readbuf, | ||
585 | 585 | || NAMELEN (dp) > sizeof ("4294967295") - 1) |
586 | 586 | continue; |
587 | 587 | |
588 | - sprintf (procentry, "/proc/%s", dp->d_name); | |
588 | + xsnprintf (procentry, sizeof (procentry), "/proc/%s", | |
589 | + dp->d_name); | |
589 | 590 | if (stat (procentry, &statbuf) == 0 |
590 | 591 | && S_ISDIR (statbuf.st_mode)) |
591 | 592 | { |
@@ -797,7 +798,8 @@ linux_xfer_osdata_fds (gdb_byte *readbuf, | ||
797 | 798 | || NAMELEN (dp) > sizeof ("4294967295") - 1) |
798 | 799 | continue; |
799 | 800 | |
800 | - sprintf (procentry, "/proc/%s", dp->d_name); | |
801 | + xsnprintf (procentry, sizeof (procentry), "/proc/%s", | |
802 | + dp->d_name); | |
801 | 803 | if (stat (procentry, &statbuf) == 0 |
802 | 804 | && S_ISDIR (statbuf.st_mode)) |
803 | 805 | { |