Fix BZ #116002.
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/NEWS b/NEWS
index 79dc0bd..b45c966 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,7 @@
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
diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c
index 1e7958b..4be1762 100644
--- a/coregrind/m_debuginfo/readdwarf3.c
+++ b/coregrind/m_debuginfo/readdwarf3.c
@@ -2018,7 +2018,7 @@
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 @@
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));
}
}
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
index 09cd033..95e4bb0 100644
--- a/coregrind/m_debuginfo/readelf.c
+++ b/coregrind/m_debuginfo/readelf.c
@@ -2383,7 +2383,7 @@
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 @@
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 @@
_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); \
diff --git a/coregrind/m_debuginfo/readexidx.c b/coregrind/m_debuginfo/readexidx.c
index ab34367..727deb3 100644
--- a/coregrind/m_debuginfo/readexidx.c
+++ b/coregrind/m_debuginfo/readexidx.c
@@ -388,7 +388,7 @@
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);
}
diff --git a/coregrind/m_debuglog.c b/coregrind/m_debuglog.c
index 47a2750..7cb1ee5 100644
--- a/coregrind/m_debuglog.c
+++ b/coregrind/m_debuglog.c
@@ -589,7 +589,7 @@
}
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 @@
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 @@
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 @@
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': ' ';
}
}
diff --git a/coregrind/m_gdbserver/target.c b/coregrind/m_gdbserver/target.c
index 1f6117c..e248228 100644
--- a/coregrind/m_gdbserver/target.c
+++ b/coregrind/m_gdbserver/target.c
@@ -116,7 +116,7 @@
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);
}
diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c
index a6a6705..7349849 100644
--- a/coregrind/m_mallocfree.c
+++ b/coregrind/m_mallocfree.c
@@ -626,7 +626,7 @@
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 @@
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,
diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c
index 8f7a4e0..a4738e2 100644
--- a/coregrind/m_redir.c
+++ b/coregrind/m_redir.c
@@ -1694,7 +1694,7 @@
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 @@
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",
diff --git a/coregrind/m_seqmatch.c b/coregrind/m_seqmatch.c
index ac4277b..57ca3b0 100644
--- a/coregrind/m_seqmatch.c
+++ b/coregrind/m_seqmatch.c
@@ -227,7 +227,7 @@
//{
// 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
diff --git a/lackey/lk_main.c b/lackey/lk_main.c
index b2ca1ff..bbd4983 100644
--- a/lackey/lk_main.c
+++ b/lackey/lk_main.c
@@ -388,7 +388,7 @@
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],
diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c
index f02e75c..6b5e844 100644
--- a/memcheck/mc_leakcheck.c
+++ b/memcheck/mc_leakcheck.c
@@ -1467,7 +1467,7 @@
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],
diff --git a/none/tests/unit_debuglog.c b/none/tests/unit_debuglog.c
index 1fecb30..1bd1d2a 100644
--- a/none/tests/unit_debuglog.c
+++ b/none/tests/unit_debuglog.c
@@ -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 @@
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 @@
fprintf(stderr, "\twrote %3d chars\n", n);
}
-
int main(int argc, char *argv[])
{
double value;
@@ -138,11 +124,30 @@
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;
}
diff --git a/none/tests/unit_debuglog.stderr.exp b/none/tests/unit_debuglog.stderr.exp
index 7e8e87a..c8dc03f 100644
--- a/none/tests/unit_debuglog.stderr.exp
+++ b/none/tests/unit_debuglog.stderr.exp
@@ -105,3 +105,25 @@
|%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