Fix -Wformat-length warning in tst-setgetname.c

Message ID 1477325277.8523.48.camel@caviumnetworks.com
State New, archived
Headers

Commit Message

Steve Ellcey Oct. 24, 2016, 4:07 p.m. UTC
  Here is another patch to fix a new warning (-Wformat-length) coming
from GCC 7.0.  If GCC thinks an snprintf might overrun the buffer being
written to, it gives a warning.  This patch increases the buffer size
so that the warning is no longer given.

OK to checkin?

Steve Ellcey
sellcey@caviumnetworks.com


2016-10-24  Steve Ellcey  <sellcey@caviumnetworks.com>

	* sysdeps/unix/sysv/linux/tst-setgetname.c: Increase buffer size.
  

Comments

Florian Weimer Oct. 24, 2016, 4:32 p.m. UTC | #1
On 10/24/2016 06:07 PM, Steve Ellcey wrote:
> 2016-10-24  Steve Ellcey  <sellcey@caviumnetworks.com>
>
> 	* sysdeps/unix/sysv/linux/tst-setgetname.c: Increase buffer size.

Okay.

Thanks,
Florian
  
Tolga Dalman Dec. 13, 2016, 12:11 a.m. UTC | #2
Hi Steve,

nice catch! Your fix is ok -- nitpicking now.

>  #define FMT "/proc/self/task/%lu/comm"
> -  char fname[sizeof (FMT) + 8];
> +  char fname[sizeof (FMT) + 32];

+ 20 is sufficient. (actually 20 - sizeof("%lu"))

>    sprintf (fname, FMT, (unsigned long) tid);

suggest to use snprintf instead.

Thanks
Tolga
  

Patch

diff --git a/sysdeps/unix/sysv/linux/tst-setgetname.c b/sysdeps/unix/sysv/linux/
tst-setgetname.c
index f490d83..30fbe4e 100644
--- a/sysdeps/unix/sysv/linux/tst-setgetname.c
+++ b/sysdeps/unix/sysv/linux/tst-setgetname.c
@@ -56,7 +56,7 @@  get_self_comm (long tid, char *buf, size_t len)
 {
   int res = 0;
 #define FMT "/proc/self/task/%lu/comm"
-  char fname[sizeof (FMT) + 8];
+  char fname[sizeof (FMT) + 32];
   sprintf (fname, FMT, (unsigned long) tid);
 
   int fd = open (fname, O_RDONLY);