This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB 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]

[binutils-gdb] Replace sprintf with xsnprintf in nat/linux-osdata.c


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=97e64e5ab19dbf6a9babd711e8deec5545520954

commit 97e64e5ab19dbf6a9babd711e8deec5545520954
Author: Yao Qi <yao.qi@linaro.org>
Date:   Fri Sep 23 17:27:26 2016 +0100

    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=]
     linux_xfer_osdata_fds (gdb_byte *readbuf,
     ^~~~~~~~~~~~~~~~~~~~~
    ../../binutils-gdb/gdb/nat/linux-osdata.c:800:51: note: format output between 7 and 262 bytes into a destination of size 17
            sprintf (procentry, "/proc/%s", dp->d_name);
                                                       ^
    ../../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=]
     linux_xfer_osdata_threads (gdb_byte *readbuf,
     ^~~~~~~~~~~~~~~~~~~~~~~~~
    ../../binutils-gdb/gdb/nat/linux-osdata.c:588:51: note: format output between 7 and 262 bytes into a destination of size 17
            sprintf (procentry, "/proc/%s", dp->d_name);
                                                       ^
    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.

Diff:
---
 gdb/ChangeLog          | 6 ++++++
 gdb/nat/linux-osdata.c | 6 ++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3826299..ce63f93 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
 2016-09-23  Pedro Alves  <palves@redhat.com>
 
 	* Makefile.in (SFILES): Add common/new-op.c.
diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c
index bf98c96..5b407a4 100644
--- a/gdb/nat/linux-osdata.c
+++ b/gdb/nat/linux-osdata.c
@@ -585,7 +585,8 @@ linux_xfer_osdata_threads (gdb_byte *readbuf,
 		  || NAMELEN (dp) > sizeof ("4294967295") - 1)
 		continue;
 
-	      sprintf (procentry, "/proc/%s", dp->d_name);
+	      xsnprintf (procentry, sizeof (procentry), "/proc/%s",
+			 dp->d_name);
 	      if (stat (procentry, &statbuf) == 0
 		  && S_ISDIR (statbuf.st_mode))
 		{
@@ -797,7 +798,8 @@ linux_xfer_osdata_fds (gdb_byte *readbuf,
 		  || NAMELEN (dp) > sizeof ("4294967295") - 1)
 		continue;
 
-	      sprintf (procentry, "/proc/%s", dp->d_name);
+	      xsnprintf (procentry, sizeof (procentry), "/proc/%s",
+			 dp->d_name);
 	      if (stat (procentry, &statbuf) == 0
 		  && S_ISDIR (statbuf.st_mode))
 		{


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