diff options
| author | Mark Wielaard <[email protected]> | 2014-01-23 00:56:41 +0100 |
|---|---|---|
| committer | Mark Wielaard <[email protected]> | 2014-01-30 10:17:15 +0100 |
| commit | f48eb6b15fee66e54b488d71738979fc608f25ee (patch) | |
| tree | 22be2f2780909d8d61df125b29de5f3f60e52e97 /src | |
| parent | 13968d9aa9990d53999b14494ed55c2d68d4ead5 (diff) | |
Use -Wformat=2 by default for all files.
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 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 18 | ||||
| -rw-r--r-- | src/Makefile.am | 6 | ||||
| -rw-r--r-- | src/nm.c | 93 | ||||
| -rw-r--r-- | src/size.c | 30 | ||||
| -rw-r--r-- | src/strings.c | 33 |
5 files changed, 101 insertions, 79 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 26a607d8..134ad905 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2014-01-22 Mark Wielaard <[email protected]> + + * 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 <[email protected]> * stack.c (show_inlines): New static boolean. diff --git a/src/Makefile.am b/src/Makefile.am index 9a78348f..e3711608 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 @@ -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 <[email protected]>, 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 @@ -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 <[email protected]>, 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; } diff --git a/src/strings.c b/src/strings.c index 084eb999..37210a74 100644 --- a/src/strings.c +++ b/src/strings.c @@ -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 <[email protected]>, 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)) { |
