[PATCH] Use -Wformat=2 by default for all files.

Petr Machata pmachata at redhat.com
Thu Jan 30 15:25:47 UTC 2014


Mark Wielaard <mjw at redhat.com> writes:

> diff --git a/backends/aarch64_regs.c b/backends/aarch64_regs.c
> index aec201f..bd10c46 100644
> --- a/backends/aarch64_regs.c
> +++ b/backends/aarch64_regs.c
> @@ -47,32 +47,48 @@ aarch64_register_info (Ebl *ebl __attribute__ ((unused)),
>      return 128;
>  
>    ssize_t
> -  regtype (const char *setname, int type, const char *fmt, int arg)
> +  regtype (const char *setname, int type, const char *rname, bool nr, int arg)

Regarding this chunk, actually this can be made simpler by using
__attribute__ ((format)).  I had thought that would be too involved, but
it's actually pretty clean IMO.  What say you?

>From 27ffb08c789ca9c4b2635ca89b4004b324fb4ea4 Mon Sep 17 00:00:00 2001
Message-Id: <27ffb08c789ca9c4b2635ca89b4004b324fb4ea4.1391095070.git.pmachata at redhat.com>
From: Petr Machata <pmachata at redhat.com>
Date: Thu, 30 Jan 2014 15:34:33 +0100
Subject: [PATCH] backends: Make aarch64_regs.c checkable by -Wprintf
Gcc: nnimap+mail.corp.redhat.com:Sent
To: elfutils-devel at lists.fedorahosted.org

---
 backends/ChangeLog      |    8 ++++++++
 backends/aarch64_regs.c |   35 +++++++++++++----------------------
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 212b9f6..2863c00 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,11 @@
+2014-01-30  Petr Machata  <pmachata at redhat.com>
+
+	* aarch64_regs.c (aarch64_register_info.regtype): Make this
+	variadic printf-like function.  Call one vsnprintf instead of two
+	snprintf's.
+	(regtyper, regtypen): Drop.
+	(aarch64_register_info): Adjust callers.
+
 2014-01-26  Mark Wielaard  <mjw at redhat.com>
 
 	* Makefile.am (arm_SRCS): Add arm_initreg.c.
diff --git a/backends/aarch64_regs.c b/backends/aarch64_regs.c
index bd10c46..7a8a678 100644
--- a/backends/aarch64_regs.c
+++ b/backends/aarch64_regs.c
@@ -33,6 +33,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <dwarf.h>
+#include <stdarg.h>
 
 #define BACKEND aarch64_
 #include "libebl_CPU.h"
@@ -46,49 +47,39 @@ aarch64_register_info (Ebl *ebl __attribute__ ((unused)),
   if (name == NULL)
     return 128;
 
+  __attribute__ ((format (printf, 3, 4)))
   ssize_t
-  regtype (const char *setname, int type, const char *rname, bool nr, int arg)
+  regtype (const char *setname, int type, const char *fmt, ...)
   {
     *setnamep = setname;
     *typep = type;
-    int s;
-    if (nr)
-      s = snprintf (name, namelen, "%s%d", rname, arg);
-    else
-      s = snprintf (name, namelen, "%s", rname);
+
+    va_list ap;
+    va_start (ap, fmt);
+    int s = vsnprintf (name, namelen, fmt, ap);
+    va_end(ap);
+
     if (s < 0 || (unsigned) s >= namelen)
       return -1;
     return s + 1;
   }
 
-  ssize_t
-  regtyper (const char *setname, int type, const char *rname)
-  {
-    return regtype (setname, type, rname, false, 0);
-  }
-
-  ssize_t
-  regtypen (const char *setname, int type, const char *rname, int arg)
-  {
-    return regtype (setname, type, rname, true, arg);
-  }
-
   *prefix = "";
   *bits = 64;
 
   switch (regno)
     {
     case 0 ... 30:
-      return regtypen ("integer", DW_ATE_signed, "x", regno);
+      return regtype ("integer", DW_ATE_signed, "x%d", regno);
 
     case 31:
-      return regtyper ("integer", DW_ATE_address, "sp");
+      return regtype ("integer", DW_ATE_address, "sp");
 
     case 32:
       return 0;
 
     case 33:
-      return regtyper ("integer", DW_ATE_address, "elr");
+      return regtype ("integer", DW_ATE_address, "elr");
 
     case 34 ... 63:
       return 0;
@@ -100,7 +91,7 @@ aarch64_register_info (Ebl *ebl __attribute__ ((unused)),
 	 integers.  128-bit quad-word is the only singular value that
 	 covers the whole register, so mark the register thus.  */
       *bits = 128;
-      return regtypen ("FP/SIMD", DW_ATE_unsigned, "v", regno - 64);
+      return regtype ("FP/SIMD", DW_ATE_unsigned, "v%d", regno - 64);
 
     case 96 ... 127:
       return 0;
-- 
1.7.6.5



More information about the elfutils-devel mailing list