]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Use -Wformat=2 by default for all files.
authorMark Wielaard <mjw@redhat.com>
Wed, 22 Jan 2014 23:56:41 +0000 (00:56 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 30 Jan 2014 09:17:15 +0000 (10:17 +0100)
This just makes sure that all format strings are given as literals to
printf like functions so the compiler can see and check them. Remove
all no_Wformat, add -Wformat=2 unconditionally to AM_CFLAGS.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
12 files changed:
backends/ChangeLog
backends/Makefile.am
backends/aarch64_regs.c
config/ChangeLog
config/eu.am
src/ChangeLog
src/Makefile.am
src/nm.c
src/size.c
src/strings.c
tests/ChangeLog
tests/Makefile.am

index a742eb259df7d2181141e76330e4e2b12c9ec343..0df68195e766d5ce2fab7bfa558160d013f5221a 100644 (file)
@@ -1,3 +1,13 @@
+2014-01-22  Mark Wielaard  <mjw@redhat.com>
+
+       * Makefile.am (aarch64_regs_no_Wformat): Removed.
+       * aarch64_regs.c (regtype): Add bool nr argument. snprintf arg
+       when nr is true.
+       (regtyper): New function.
+       (regtypen): Likewise.
+       (aarch64_register_info): Call either regtyper or regtypen not
+       regtype directly.
+
 2014-01-14  Mark Wielaard  <mjw@redhat.com>
 
        * aarch64_symbol.c (aarch64_check_special_symbol): Check shdr is
index b8bea36b1d108544e1fbc4ed859eabc67e6ce85a..90e93a88ba74e9573aa1e6d1da8820288810fdb6 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 2000-2010, 2013 Red Hat, Inc.
+## Copyright (C) 2000-2010, 2013, 2014 Red Hat, Inc.
 ## Copyright (C) 2012 Tilera Corporation
 ## This file is part of elfutils.
 ##
@@ -86,7 +86,6 @@ aarch64_SRCS = aarch64_init.c aarch64_regs.c aarch64_symbol.c \
               aarch64_corenote.c aarch64_retval.c aarch64_cfi.c
 libebl_aarch64_pic_a_SOURCES = $(aarch64_SRCS)
 am_libebl_aarch64_pic_a_OBJECTS = $(aarch64_SRCS:.c=.os)
-aarch64_regs_no_Wformat = yes
 
 sparc_SRCS = sparc_init.c sparc_symbol.c sparc_regs.c sparc_retval.c \
             sparc_corenote.c sparc64_corenote.c sparc_auxv.c
index aec201f3d08c0bac7d7e4bc523aa7a5dcf611155..bd10c464e8755482807185deb844a3135b4c36b5 100644 (file)
@@ -1,5 +1,5 @@
 /* Register names and numbers for AArch64 DWARF.
-   Copyright (C) 2013 Red Hat, Inc.
+   Copyright (C) 2013, 2014 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -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)
   {
     *setnamep = setname;
     *typep = type;
-    int s = snprintf (name, namelen, fmt, arg);
+    int s;
+    if (nr)
+      s = snprintf (name, namelen, "%s%d", rname, arg);
+    else
+      s = snprintf (name, namelen, "%s", rname);
     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 regtype ("integer", DW_ATE_signed, "x%d", regno);
+      return regtypen ("integer", DW_ATE_signed, "x", regno);
 
     case 31:
-      return regtype ("integer", DW_ATE_address, "sp", 0);
+      return regtyper ("integer", DW_ATE_address, "sp");
 
     case 32:
       return 0;
 
     case 33:
-      return regtype ("integer", DW_ATE_address, "elr", 0);
+      return regtyper ("integer", DW_ATE_address, "elr");
 
     case 34 ... 63:
       return 0;
@@ -84,7 +100,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 regtype ("FP/SIMD", DW_ATE_unsigned, "v%d", regno - 64);
+      return regtypen ("FP/SIMD", DW_ATE_unsigned, "v", regno - 64);
 
     case 96 ... 127:
       return 0;
index 53fddec6339ff7e4a1049b386457c95e4c99c4ca..0fca489a3b06235ff6840c44d72b3f9d17eb5f72 100644 (file)
@@ -1,3 +1,7 @@
+2014-01-22  Mark Wielaard  <mjw@redhat.com>
+
+       * eu.am (AM_CFLAGS): Unconditionally add -Wformat=2.
+
 2014-01-03  Mark Wielaard  <mjw@redhat.com>
 
        * elfutils.spec.in: Update for 0.158.
index 38718c7f3efa9cfc458ad143aeb8383a9193aee8..d2b4e79554ab27d77003968b57b9f611fdafa53d 100644 (file)
@@ -1,6 +1,6 @@
 ## Common automake fragments for elfutils subdirectory makefiles.
 ##
-## Copyright (C) 2010 Red Hat, Inc.
+## Copyright (C) 2010, 2014 Red Hat, Inc.
 ##
 ## This file is part of elfutils.
 ##
 
 DEFS = -D_GNU_SOURCE -DHAVE_CONFIG_H -DLOCALEDIR='"${localedir}"'
 AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_srcdir)/lib -I..
-AM_CFLAGS = -std=gnu99 -Wall -Wshadow \
+AM_CFLAGS = -std=gnu99 -Wall -Wshadow -Wformat=2 \
            $(if $($(*F)_no_Werror),,-Werror) \
            $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
-           $(if $($(*F)_no_Wformat),-Wno-format,-Wformat=2) \
            $($(*F)_CFLAGS)
 
 if MUDFLAP
index 26a607d8b4f63fc6ba846f9895024954bed825fc..134ad9053725d6374d5d7eb2bff81e9ff505917b 100644 (file)
@@ -1,3 +1,21 @@
+2014-01-22  Mark Wielaard  <mjw@redhat.com>
+
+       * Makefile.am (nm_no_Wformat): Removed.
+       (size_no_Wformat): Likewise.
+       (strings_no_Wformat): Likewise.
+       (addr2line_no_Wformat): Likewise.
+       * size.c (show_sysv): Use fmtstr directly as literal in printf.
+       (show_sysv_one_line): Likewise.
+       * strings.c (locfmt): Removed.
+       (radix): New static enum.
+       (parse_opt): Set radix, not locfmt.
+       (process_chunk_mb): Use fmtstr directly as literal in printf based
+       on radix.
+       (process_chunk): Likewise.
+       * nm.c (show_symbols_sysv): Use fmtstr directly as literal in printf.
+       (show_symbols_bsd): Likewise.
+       (show_symbols_posix): Likewise.
+
 2014-01-21  Mark Wielaard  <mjw@redhat.com>
 
        * stack.c (show_inlines): New static boolean.
index 9a78348fced804618d80db9b6cd2558ccfcb7f5b..e371160899bad85f0d996d0c0c2f588167e2dff9 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 ##
-## Copyright (C) 1996-2013 Red Hat, Inc.
+## Copyright (C) 1996-2014 Red Hat, Inc.
 ## This file is part of elfutils.
 ##
 ## This file is free software; you can redistribute it and/or modify
@@ -88,10 +88,6 @@ if DEMANGLE
 demanglelib = -lstdc++
 endif
 
-nm_no_Wformat = yes
-size_no_Wformat = yes
-strings_no_Wformat = yes
-addr2line_no_Wformat = yes
 # XXX While the file is not finished, don't warn about this
 ldgeneric_no_Wunused = yes
 
index 62efb2d0f4246c52b85a4cf955332b68c155688a..4f2e0e7858e496807efdb1769da8c5d6e4342e67 100644 (file)
--- a/src/nm.c
+++ b/src/nm.c
@@ -1,5 +1,5 @@
 /* Print symbol information from ELF file in human-readable form.
-   Copyright (C) 2000-2008, 2009, 2011, 2012 Red Hat, Inc.
+   Copyright (C) 2000-2008, 2009, 2011, 2012, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -794,15 +794,6 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname,
          /* TRANS: the "sysv|" parts makes the string unique.  */
          longest_where, sgettext ("sysv|Line"));
 
-  /* Which format string to use (different radix for numbers).  */
-  const char *number_fmtstr;
-  if (radix == radix_hex)
-    number_fmtstr = "%0*" PRIx64;
-  else if (radix == radix_decimal)
-    number_fmtstr = "%0*" PRId64;
-  else
-    number_fmtstr = "%0*" PRIo64;
-
 #ifdef USE_DEMANGLE
   size_t demangle_buffer_len = 0;
   char *demangle_buffer = NULL;
@@ -850,9 +841,15 @@ show_symbols_sysv (Ebl *ebl, GElf_Word strndx, const char *fullname,
        addressbuf[0] = sizebuf[0] = '\0';
       else
        {
-         snprintf (addressbuf, sizeof (addressbuf), number_fmtstr,
+         snprintf (addressbuf, sizeof (addressbuf),
+                   (radix == radix_hex ? "%0*" PRIx64
+                    : (radix == radix_decimal ? "%0*" PRId64
+                       : "%0*" PRIo64)),
                    digits, syms[cnt].sym.st_value);
-         snprintf (sizebuf, sizeof (sizebuf), number_fmtstr,
+         snprintf (sizebuf, sizeof (sizebuf),
+                   (radix == radix_hex ? "%0*" PRIx64
+                    : (radix == radix_decimal ? "%0*" PRId64
+                       : "%0*" PRIo64)),
                    digits, syms[cnt].sym.st_size);
        }
 
@@ -929,19 +926,6 @@ show_symbols_bsd (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx,
   if (prefix != NULL && ! print_file_name)
     printf ("\n%s:\n", fname);
 
-  static const char *const fmtstrs[] =
-    {
-      [radix_hex] = "%6$s%2$0*1$" PRIx64 "%8$s %7$s%3$c%4$s %5$s",
-      [radix_decimal] = "%6$s%*" PRId64 "%8$s %7$s%3$c%4$s %5$s",
-      [radix_octal] = "%6$s%2$0*1$" PRIo64 "%8$s %7$s%3$c%4$s %5$s"
-    };
-  static const char *const sfmtstrs[] =
-    {
-      [radix_hex] = "%6$s%2$0*1$" PRIx64 "%8$s %10$0*9$" PRIx64 " %7$s%3$c%4$s %5$s",
-      [radix_decimal] = "%6$s%2$*1$" PRId64 "%8$s %10$*9$" PRId64 " %7$s%3$c%4$s %5$s",
-      [radix_octal] = "%6$s%2$0*1$" PRIo64 "%8$s %10$0*9$" PRIo64 " %7$s%3$c%4$s %5$s"
-    };
-
 #ifdef USE_DEMANGLE
   size_t demangle_buffer_len = 0;
   char *demangle_buffer = NULL;
@@ -1016,16 +1000,41 @@ show_symbols_bsd (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx,
              else
                color = color_symbol;
            }
-
-         printf (print_size && syms[cnt].sym.st_size != 0
-                 ? sfmtstrs[radix] : fmtstrs[radix],
-                 digits, syms[cnt].sym.st_value,
-                 class_type_char (elf, ehdr, &syms[cnt].sym), marker,
-                 symstr,
-                 color_mode ? color_address : "",
-                 color,
-                 color_mode ? color_off : "",
-                 digits, (uint64_t) syms[cnt].sym.st_size);
+         if (print_size && syms[cnt].sym.st_size != 0)
+           {
+#define HEXFMT "%6$s%2$0*1$" PRIx64 "%8$s %10$0*9$" PRIx64 " %7$s%3$c%4$s %5$s"
+#define DECFMT "%6$s%2$*1$" PRId64 "%8$s %10$*9$" PRId64 " %7$s%3$c%4$s %5$s"
+#define OCTFMT "%6$s%2$0*1$" PRIo64 "%8$s %10$0*9$" PRIo64 " %7$s%3$c%4$s %5$s"
+             printf ((radix == radix_hex ? HEXFMT
+                      : (radix == radix_decimal ? DECFMT : OCTFMT)),
+                     digits, syms[cnt].sym.st_value,
+                     class_type_char (elf, ehdr, &syms[cnt].sym), marker,
+                     symstr,
+                     color_mode ? color_address : "",
+                     color,
+                     color_mode ? color_off : "",
+                     digits, (uint64_t) syms[cnt].sym.st_size);
+#undef HEXFMT
+#undef DECFMT
+#undef OCTFMT
+           }
+         else
+           {
+#define HEXFMT "%6$s%2$0*1$" PRIx64 "%8$s %7$s%3$c%4$s %5$s"
+#define DECFMT "%6$s%2$*1$" PRId64 "%8$s %7$s%3$c%4$s %5$s"
+#define OCTFMT "%6$s%2$0*1$" PRIo64 "%8$s %7$s%3$c%4$s %5$s"
+             printf ((radix == radix_hex ? HEXFMT
+                      : (radix == radix_decimal ? DECFMT : OCTFMT)),
+                     digits, syms[cnt].sym.st_value,
+                     class_type_char (elf, ehdr, &syms[cnt].sym), marker,
+                     symstr,
+                     color_mode ? color_address : "",
+                     color,
+                     color_mode ? color_off : "");
+#undef HEXFMT
+#undef DECFMT
+#undef OCTFMT
+           }
        }
 
       if (color_mode)
@@ -1047,14 +1056,6 @@ show_symbols_posix (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx,
   if (prefix != NULL && ! print_file_name)
     printf ("%s:\n", fullname);
 
-  const char *fmtstr;
-  if (radix == radix_hex)
-    fmtstr = "%s %c%s %0*" PRIx64 " %0*" PRIx64 "\n";
-  else if (radix == radix_decimal)
-    fmtstr = "%s %c%s %*" PRId64 " %*" PRId64 "\n";
-  else
-    fmtstr = "%s %c%s %0*" PRIo64 " %0*" PRIo64 "\n";
-
   int digits = length_map[gelf_getclass (elf) - 1][radix];
 
 #ifdef USE_DEMANGLE
@@ -1096,7 +1097,11 @@ show_symbols_posix (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx,
          putchar_unlocked (' ');
        }
 
-      printf (fmtstr,
+      printf ((radix == radix_hex
+              ? "%s %c%s %0*" PRIx64 " %0*" PRIx64 "\n"
+              : (radix == radix_decimal
+                 ? "%s %c%s %*" PRId64 " %*" PRId64 "\n"
+                 : "%s %c%s %0*" PRIo64 " %0*" PRIo64 "\n")),
              symstr,
              class_type_char (elf, ehdr, &syms[cnt].sym),
              mark_special
index dfa46b1fb57f6ad7f0d1e483c1cd3ee0478e8b17..9db55c80d513fa1fa52ccad0b7fdbb65413bcc33 100644 (file)
@@ -1,5 +1,5 @@
 /* Print size information from ELF file.
-   Copyright (C) 2000-2007,2009,2012 Red Hat, Inc.
+   Copyright (C) 2000-2007,2009,2012,2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -441,14 +441,6 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
          digits - 2, sgettext ("sysv|size"),
          digits, sgettext ("sysv|addr"));
 
-  const char *fmtstr;
-  if (radix == radix_hex)
-    fmtstr = "%-*s %*" PRIx64 " %*" PRIx64 "\n";
-  else if (radix == radix_decimal)
-    fmtstr = "%-*s %*" PRId64 " %*" PRId64 "\n";
-  else
-    fmtstr = "%-*s %*" PRIo64 " %*" PRIo64 "\n";
-
   /* Iterate over all sections.  */
   GElf_Off total = 0;
   while ((scn = elf_nextscn (elf, scn)) != NULL)
@@ -459,7 +451,11 @@ show_sysv (Elf *elf, const char *prefix, const char *fname,
       /* Ignore all sections which are not used at runtime.  */
       if ((shdr->sh_flags & SHF_ALLOC) != 0)
        {
-         printf (fmtstr,
+         printf ((radix == radix_hex
+                  ? "%-*s %*" PRIx64 " %*" PRIx64 "\n"
+                  : (radix == radix_decimal
+                     ? "%-*s %*" PRId64 " %*" PRId64 "\n"
+                     : "%-*s %*" PRIo64 " %*" PRIo64 "\n")),
                  maxlen, elf_strptr (elf, shstrndx, shdr->sh_name),
                  digits - 2, shdr->sh_size,
                  digits, shdr->sh_addr);
@@ -490,14 +486,6 @@ show_sysv_one_line (Elf *elf)
     error (EXIT_FAILURE, 0,
           gettext ("cannot get section header string table index"));
 
-  const char *fmtstr;
-  if (radix == radix_hex)
-    fmtstr = "%" PRIx64 "(%s)";
-  else if (radix == radix_decimal)
-    fmtstr = "%" PRId64 "(%s)";
-  else
-    fmtstr = "%" PRIo64 "(%s)";
-
   /* Iterate over all sections.  */
   GElf_Off total = 0;
   bool first = true;
@@ -515,8 +503,10 @@ show_sysv_one_line (Elf *elf)
        fputs_unlocked (" + ", stdout);
       first = false;
 
-      printf (fmtstr, shdr->sh_size,
-             elf_strptr (elf, shstrndx, shdr->sh_name));
+      printf ((radix == radix_hex ? "%" PRIx64 "(%s)"
+              : (radix == radix_decimal ? "%" PRId64 "(%s)"
+                 : "%" PRIo64 "(%s)")),
+             shdr->sh_size, elf_strptr (elf, shstrndx, shdr->sh_name));
 
       total += shdr->sh_size;
     }
index 084eb999ffe896986ee632b1ae73e0362ea2c8de..37210a74bd3b46322db3548059e9ddc8ad75598b 100644 (file)
@@ -1,5 +1,5 @@
 /* Print the strings of printable characters in files.
-   Copyright (C) 2005-2010, 2012 Red Hat, Inc.
+   Copyright (C) 2005-2010, 2012, 2014 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2005.
 
@@ -116,8 +116,15 @@ static bool char_7bit;
 /* True if file names should be printed before strings.  */
 static bool print_file_name;
 
-/* Location print format string.  */
-static const char *locfmt;
+/* Radix for printed numbers.  */
+static enum
+{
+  radix_none = 0,
+  radix_decimal,
+  radix_hex,
+  radix_octal
+} radix = radix_none;
+
 
 /* Page size in use.  */
 static size_t ps;
@@ -279,16 +286,16 @@ parse_opt (int key, char *arg,
       switch (arg[0])
        {
        case 'd':
-         locfmt = "%7" PRId64 " ";
+         radix = radix_decimal;
          break;
 
        case 'o':
        octfmt:
-         locfmt = "%7" PRIo64 " ";
+         radix = radix_octal;
          break;
 
        case 'x':
-         locfmt = "%7" PRIx64 " ";
+         radix = radix_hex;
          break;
 
        default:
@@ -355,8 +362,11 @@ process_chunk_mb (const char *fname, const unsigned char *buf, off64_t to,
                  fputs_unlocked (": ", stdout);
                }
 
-             if (unlikely (locfmt != NULL))
-               printf (locfmt, (int64_t) to - len - (buf - start));
+             if (unlikely (radix != radix_none))
+               printf ((radix == radix_octal ? "%7" PRIo64 " "
+                        : (radix == radix_decimal ? "%7" PRId64 " "
+                           : "%7" PRIx64 " ")),
+                       (int64_t) to - len - (buf - start));
 
              if (unlikely (*unprinted != NULL))
                {
@@ -420,8 +430,11 @@ process_chunk (const char *fname, const unsigned char *buf, off64_t to,
                  fputs_unlocked (": ", stdout);
                }
 
-             if (likely (locfmt != NULL))
-               printf (locfmt, (int64_t) to - len - (buf - start));
+             if (likely (radix != radix_none))
+               printf ((radix == radix_octal ? "%7" PRIo64 " "
+                        : (radix == radix_decimal ? "%7" PRId64 " "
+                           : "%7" PRIx64 " ")),
+                       (int64_t) to - len - (buf - start));
 
              if (unlikely (*unprinted != NULL))
                {
index aa468c44271dc4ac822160f40d85c3628e39cbdf..cbf26725804da42716a42850cac158bfad3dc966 100644 (file)
@@ -1,3 +1,7 @@
+2014-01-22  Mark Wielaard  <mjw@redhat.com>
+
+       * Makefile.am (line2addr_no_Wformat): Removed.
+
 2014-01-21  Mark Wielaard  <mjw@redhat.com>
 
        * Makefile.am (TESTS): Add run-stack-i-test.sh.
index aa13cfa35a1b3132664c3f8a988e56f812807cd9..c75e7969fb11666c30713c0eed384db9713b8aa9 100644 (file)
@@ -355,7 +355,6 @@ get_lines_LDADD = $(libdw) $(libelf) $(libmudflap)
 get_files_LDADD = $(libdw) $(libelf) $(libmudflap)
 get_aranges_LDADD = $(libdw) $(libelf) $(libmudflap)
 allfcts_LDADD = $(libdw) $(libelf) $(libmudflap)
-line2addr_no_Wformat = yes
 line2addr_LDADD = $(libdw) $(libmudflap)
 addrscopes_LDADD = $(libdw) $(libmudflap)
 funcscopes_LDADD = $(libdw) $(libmudflap)