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
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
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) {
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));
}
}
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. */ \
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); \
_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); \
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);
}
}
extra = width - len;
- if (flags & VG_MSG_LJUSTIFY) {
+ if (! (flags & VG_MSG_LJUSTIFY)) {
ret += extra;
for (i = 0; i < extra; i++)
send(' ', send_arg2);
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);
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;
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': ' ';
}
}
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);
}
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,"
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,
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",
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",
//{
// 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
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],
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],
void run(const char *format, ...)
{
- int n, num_stars, i1, i2;
+ int n, num_stars;
const char *p;
printf_buf buf;
va_list vargs;
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);
fprintf(stderr, "\twrote %3d chars\n", n);
}
-
int main(int argc, char *argv[])
{
double value;
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;
}
|%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