]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix BZ #116002.
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 13 Dec 2014 18:35:00 +0000 (18:35 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 13 Dec 2014 18:35:00 +0000 (18:35 +0000)
Left justification of strings in myvprintf_str was mixed up.
Now fixed and %s formats changed accordingly.
In function myvprintf_int64: the local buffer was not large
enough to hold ULONG_MAX in binary notation. Numbers were
truncated at 39 digits.
Testcases added.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14808

13 files changed:
NEWS
coregrind/m_debuginfo/readdwarf3.c
coregrind/m_debuginfo/readelf.c
coregrind/m_debuginfo/readexidx.c
coregrind/m_debuglog.c
coregrind/m_gdbserver/target.c
coregrind/m_mallocfree.c
coregrind/m_redir.c
coregrind/m_seqmatch.c
lackey/lk_main.c
memcheck/mc_leakcheck.c
none/tests/unit_debuglog.c
none/tests/unit_debuglog.stderr.exp

diff --git a/NEWS b/NEWS
index 79dc0bdb601660ac1ceca5700a044694dd4f6d27..b45c9663ec423e45851965e136e591fdb5785dad 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,7 @@ To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
 where XXXXXX is the bug number as listed below.
 
+116002  VG_(printf): Problems with justification of strings and integers
 155125  avoid cutting away file:lineno after long function name
 211926  Avoid compilation warnings in valgrind.h with -pedantic
 269360  s390x: Fix addressing mode selection for compare-and-swap
index 1e7958babc7953eaba0a41640cbe4b68fd0ac3ec..4be17620cc1b24816efc8d5055ca7b00830f7f3c 100644 (file)
@@ -2018,7 +2018,7 @@ static void trace_DIE(
       DW_FORM form = (DW_FORM)abbv->nf[nf_i].at_form;
       nf_i++;
       if (attr == 0 && form == 0) break;
-      VG_(printf)("     %18s: ", ML_(pp_DW_AT)(attr));
+      VG_(printf)("     %-18s: ", ML_(pp_DW_AT)(attr));
       /* Get the form contents, so as to print them */
       get_Form_contents( &cts, cc, &c, True, form );
       if (attr == DW_AT_sibling && cts.szB > 0) {
@@ -4451,7 +4451,7 @@ static void trace_debug_abbrev (const DebugInfo* di,
                ULong at_name = get_ULEB128( &abbv );
                ULong at_form = get_ULEB128( &abbv );
                if (at_name == 0 && at_form == 0) break;
-               TRACE_D3("    %18s %s\n", 
+               TRACE_D3("    %-18s %s\n", 
                         ML_(pp_DW_AT)(at_name), ML_(pp_DW_FORM)(at_form));
             }
          }
index 09cd03339643698027a9556d0014f7ab31ef9c70..95e4bb00b2c35a4d0486802044e1997e46678757 100644 (file)
@@ -2383,7 +2383,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
                nobits         = a_shdr.sh_type == SHT_NOBITS; \
                vg_assert(_sec_escn.img  != NULL); \
                vg_assert(_sec_escn.ioff != DiOffT_INVALID); \
-               TRACE_SYMTAB( "%18s:  ioff %llu .. %llu\n", \
+               TRACE_SYMTAB( "%-18s:  ioff %llu .. %llu\n", \
                              _sec_name, (ULong)_sec_escn.ioff, \
                              ((ULong)_sec_escn.ioff) + _sec_escn.szB - 1); \
                /* SHT_NOBITS sections have zero size in the file. */ \
@@ -2677,7 +2677,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
                   nobits         = a_shdr.sh_type == SHT_NOBITS; \
                   vg_assert(_sec_escn.img  != NULL); \
                   vg_assert(_sec_escn.ioff != DiOffT_INVALID); \
-                  TRACE_SYMTAB( "%18s: dioff %llu .. %llu\n", \
+                  TRACE_SYMTAB( "%-18s: dioff %llu .. %llu\n", \
                                 _sec_name, \
                                 (ULong)_sec_escn.ioff, \
                                 ((ULong)_sec_escn.ioff) + _sec_escn.szB - 1); \
@@ -2820,7 +2820,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
                   _sec_escn.szB  = a_shdr.sh_size; \
                   vg_assert(_sec_escn.img  != NULL); \
                   vg_assert(_sec_escn.ioff != DiOffT_INVALID); \
-                  TRACE_SYMTAB( "%18s: aioff %llu .. %llu\n", \
+                  TRACE_SYMTAB( "%-18s: aioff %llu .. %llu\n", \
                                 _sec_name, \
                                 (ULong)_sec_escn.ioff, \
                                 ((ULong)_sec_escn.ioff) + _sec_escn.szB - 1); \
index ab343679f88d09936c3b27c89089bd43dc4a1f2b..727deb32c8696932ecb277cefba86dc8b4884db3 100644 (file)
@@ -388,7 +388,7 @@ typedef
    ExtabData;
 
 static void ppExtabData ( const ExtabData* etd ) {
-   VG_(printf)("ExtabData{%12s 0x%08x}", showExtabCmd(etd->cmd), etd->data);
+   VG_(printf)("ExtabData{%-12s 0x%08x}", showExtabCmd(etd->cmd), etd->data);
 }
 
 
index 47a27500f4415601a2b0946bb2ff41c2c567c895..7cb1ee5db23509b4c7876aa110abcf4787d40b7b 100644 (file)
@@ -589,7 +589,7 @@ UInt myvprintf_str ( void(*send)(HChar,void*),
    }
 
    extra = width - len;
-   if (flags & VG_MSG_LJUSTIFY) {
+   if (! (flags & VG_MSG_LJUSTIFY)) {
       ret += extra;
       for (i = 0; i < extra; i++)
          send(' ', send_arg2);
@@ -597,7 +597,7 @@ UInt myvprintf_str ( void(*send)(HChar,void*),
    ret += len;
    for (i = 0; i < len; i++)
       send(MAYBE_TOUPPER(str[i]), send_arg2);
-   if (!(flags & VG_MSG_LJUSTIFY)) {
+   if (flags & VG_MSG_LJUSTIFY) {
       ret += extra;
       for (i = 0; i < extra; i++)
          send(' ', send_arg2);
@@ -658,7 +658,10 @@ UInt myvprintf_int64 ( void(*send)(HChar,void*),
                        Bool capitalised,
                        ULong p )
 {
-   HChar  buf[40];
+   /* To print an ULong base 2 needs 64 characters. If commas are requested,
+      add 21. Plus 1 for a possible sign plus 1 for \0. Makes 87 -- so let's
+      say 90. The size of BUF needs to be max(90, WIDTH + 1) */
+   HChar  buf[width + 1 > 90 ? width + 1 : 90];
    Int    ind = 0;
    Int    i, nc = 0;
    Bool   neg = False;
@@ -693,11 +696,6 @@ UInt myvprintf_int64 ( void(*send)(HChar,void*),
 
    if (width > 0 && !(flags & VG_MSG_LJUSTIFY)) {
       for(; ind < width; ind++) {
-         /* vg_assert(ind < 39); */
-         if (ind > 39) {
-            buf[39] = 0;
-            break;
-         }
          buf[ind] = (flags & VG_MSG_ZJUSTIFY) ? '0': ' ';
       }
    }
index 1f6117cf72056e43a3d8ce48813525d3c2690998..e24822823aaa2581c2a3bb3f41305ca336d999d5 100644 (file)
@@ -116,7 +116,7 @@ struct reg* build_shadow_arch (struct reg *reg_defs, int n) {
          new_regs[i*n + r].offset = i*reg_set_len + reg_defs[r].offset;
          new_regs[i*n + r].size = reg_defs[r].size;
          dlog(1,
-              "%10s Nr %d offset(bit) %d offset(byte) %d  size(bit) %d\n",
+              "%-10s Nr %d offset(bit) %d offset(byte) %d  size(bit) %d\n",
               new_regs[i*n + r].name, i*n + r, new_regs[i*n + r].offset,
               (new_regs[i*n + r].offset) / 8, new_regs[i*n + r].size);
       }  
index a6a6705402126ae65f5bc3079b469ec8f9d2623e..7349849f1e28353141251d825b8a00fa47bdd2eb 100644 (file)
@@ -626,7 +626,7 @@ void VG_(print_all_arena_stats) ( void )
    for (i = 0; i < VG_N_ARENAS; i++) {
       Arena* a = arenaId_to_ArenaP(i);
       VG_(message)(Vg_DebugMsg,
-                   "%8s: %8lu/%8lu  max/curr mmap'd, "
+                   "%-8s: %8lu/%8lu  max/curr mmap'd, "
                    "%llu/%llu unsplit/split sb unmmap'd,  "
                    "%8lu/%8lu max/curr,  "
                    "%10llu/%10llu totalloc-blocks/bytes,"
@@ -1358,7 +1358,7 @@ static void sanity_check_malloc_arena ( ArenaId aid )
 
    if (VG_(clo_verbosity) > 2) 
       VG_(message)(Vg_DebugMsg,
-                   "%8s: %2d sbs, %5d bs, %2d/%-2d free bs, "
+                   "%-8s: %2d sbs, %5d bs, %2d/%-2d free bs, "
                    "%7ld mmap, %7ld loan\n",
                    a->name,
                    superblockctr,
index 8f7a4e0e84da18ff63d21b79831709a864cedec9..a4738e2427453dfaac045cd1c1b81890accbf7bb 100644 (file)
@@ -1694,7 +1694,7 @@ static void handle_require_text_symbols ( const DebugInfo* di )
 static void show_spec ( const HChar* left, const Spec* spec )
 {
    VG_(message)( Vg_DebugMsg, 
-                 "%s%25s %30s %s-> (%04d.%d) 0x%08llx\n",
+                 "%s%-25s %-30s %s-> (%04d.%d) 0x%08llx\n",
                  left,
                  spec->from_sopatt, spec->from_fnpatt,
                  spec->isWrap ? "W" : "R",
@@ -1717,7 +1717,7 @@ static void show_active ( const HChar* left, const Active* act )
    ok = VG_(get_fnname_w_offset)(act->to_addr, &name2);
    if (!ok) name2 = "???";
 
-   VG_(message)(Vg_DebugMsg, "%s0x%08llx (%20s) %s-> (%04d.%d) 0x%08llx %s\n", 
+   VG_(message)(Vg_DebugMsg, "%s0x%08llx (%-20s) %s-> (%04d.%d) 0x%08llx %s\n", 
                              left, 
                              (ULong)act->from_addr, name1,
                              act->isWrap ? "W" : "R",
index ac4277becddf8a813e93ee715039913a4e247316..57ca3b0ccb4aba778d0e399f31ca26975b84e844 100644 (file)
@@ -227,7 +227,7 @@ Bool VG_(string_match) ( const HChar* patt, const HChar* input )
 //{
 //   Test* t;
 //   for (t = tests; t->patt; t++) {
-//     printf("%10s %6s  %s\n",
+//     printf("%-10s %-6s  %s\n",
 //            t->patt, t->input, 
 //            match_string_all((UChar*)t->patt,(UChar*)t->input,True) 
 //            == t->xres
index b2ca1ff0e57e5ec62668e5713515bd8b4bc92803..bbd4983f900c89052c9b87828dff9854932d910f 100644 (file)
@@ -388,7 +388,7 @@ static void print_details ( void )
    VG_(umsg)("   Type        Loads       Stores       AluOps\n");
    VG_(umsg)("   -------------------------------------------\n");
    for (typeIx = 0; typeIx < N_TYPES; typeIx++) {
-      VG_(umsg)("   %4s %'12llu %'12llu %'12llu\n",
+      VG_(umsg)("   %-4s %'12llu %'12llu %'12llu\n",
                 nameOfTypeIndex( typeIx ),
                 detailCounts[OpLoad ][typeIx],
                 detailCounts[OpStore][typeIx],
index f02e75c867bda1f66ddd0351fa8fa761418b9f27..6b5e844f40ea344038c8a4e2351f90bc93d05392 100644 (file)
@@ -1467,7 +1467,7 @@ static void print_results(ThreadId tid, LeakCheckParams* lcp)
       for (i = 0; i < N_LEAK_CHECK_HEURISTICS; i++)
          if (old_blocks_heuristically_reachable[i] > 0 
              || MC_(blocks_heuristically_reachable)[i] > 0)
-            VG_(umsg)("                        %19s: "
+            VG_(umsg)("                        %-19s: "
                       "%'lu%s bytes in %'lu%s blocks\n",
                       pp_heuristic(i),
                       MC_(bytes_heuristically_reachable)[i], 
index 1fecb3031fe73e80f30676faf16d6c89cc2d3d2a..1bd1d2af1d868e48039385e7b9f49b8544eb63cd 100644 (file)
@@ -18,7 +18,7 @@
 
 void run(const char *format, ...)
 {
-  int n, num_stars, i1, i2;
+  int n, num_stars;
   const char *p;
   printf_buf buf;
   va_list vargs;
@@ -30,20 +30,7 @@ void run(const char *format, ...)
 
   va_start(vargs, format);
   fprintf(stderr, "%s\tprintf =   ", format);
-  switch (num_stars) {
-  case 0:
-    n = fprintf(stderr, format, va_arg(vargs, Double));
-    break;
-  case 1:
-    i1 = va_arg(vargs, int);
-    n = fprintf(stderr, format, i1, va_arg(vargs, Double));
-    break;
-  case 2:
-    i1 = va_arg(vargs, int);
-    i2 = va_arg(vargs, int);
-    n = fprintf(stderr, format, i1, i2, va_arg(vargs, Double));
-    break;
-  }
+  n = vfprintf(stderr, format, vargs);
   fprintf(stderr, "\twrote %3d chars\n", n);
   va_end(vargs);
 
@@ -59,7 +46,6 @@ void run(const char *format, ...)
   fprintf(stderr, "\twrote %3d chars\n", n);
 }
 
-
 int main(int argc, char *argv[])
 {
   double value;
@@ -138,11 +124,30 @@ int main(int argc, char *argv[])
   run("|%*.*f|", 20, 5, value);
   run("|%*.*f|", 1, 4, value);
 
-
   fprintf(stderr, "\n");
   fprintf(stderr, "...testing left justification\n");
   value = 3.1415;
   run("|%10f|", value);
   run("|%-10f|", value);
+
+  fprintf(stderr, "\n");
+  fprintf(stderr, "...testing strings\n");
+  const char *str = "abcd";
+  run("|%s|", str);
+  run("|%9s|", str);
+  run("|%-9s|", str);
+  run("|%*s|", 6, str);
+  
+  fprintf(stderr, "\n");
+  fprintf(stderr, "...testing integers\n");
+  long long ival = -1004005;
+  run("|%lld|", ival);
+  //  runint("|%'lld|", ival);     // locale specific (LC_NUMERIC)
+  run("|%15lld|", ival);
+  run("|%-15lld|", ival);
+  //  runint("|%'-15lld|", ival);  // locale specific (LC_NUMERIC)
+  run("|%100lld|", ival);
+  run("|%*lld|", 13, ival);
+
   return 0;
 }
index 7e8e87ac847d977f4b52949e4bae0104a9a8d5d6..c8dc03f6b4fc6889b587402b14ad7dfaeefdd3c6 100644 (file)
 |%10f| debuglog = |  3.141500| wrote  12 chars
 |%-10f|        printf =   |3.141500  | wrote  12 chars
 |%-10f|        debuglog = |3.141500  | wrote  12 chars
+
+...testing strings
+|%s|   printf =   |abcd|       wrote   6 chars
+|%s|   debuglog = |abcd|       wrote   6 chars
+|%9s|  printf =   |     abcd|  wrote  11 chars
+|%9s|  debuglog = |     abcd|  wrote  11 chars
+|%-9s| printf =   |abcd     |  wrote  11 chars
+|%-9s| debuglog = |abcd     |  wrote  11 chars
+|%*s|  printf =   |  abcd|     wrote   8 chars
+|%*s|  debuglog = |  abcd|     wrote   8 chars
+
+...testing integers
+|%lld| printf =   |-1004005|   wrote  10 chars
+|%lld| debuglog = |-1004005|   wrote  10 chars
+|%15lld|       printf =   |       -1004005|    wrote  17 chars
+|%15lld|       debuglog = |       -1004005|    wrote  17 chars
+|%-15lld|      printf =   |-1004005       |    wrote  17 chars
+|%-15lld|      debuglog = |-1004005       |    wrote  17 chars
+|%100lld|      printf =   |                                                                                            -1004005|       wrote 102 chars
+|%100lld|      debuglog = |                                                                                            -1004005|       wrote 102 chars
+|%*lld|        printf =   |     -1004005|      wrote  15 chars
+|%*lld|        debuglog = |     -1004005|      wrote  15 chars