Actions
Bug #848
closedctf-text: negative signed 32-bit integers are incorrectly printed
Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
10/22/2014
Due date:
% Done:
100%
Estimated time:
Description
(This was reported by Sébastien Boisvert <boisvert@anl.gov>)
fprintf()
's PRI*
conversion specifications are used whatever the integer's size in formats/ctf-text/types/integer.c
, e.g.:
case 8: { uint64_t v; if (!integer_declaration->signedness) v = integer_definition->value._unsigned; else v = (uint64_t) integer_definition->value._signed; fprintf(pos->fp, "0%" PRIo64, v); break; } case 16: { uint64_t v; if (!integer_declaration->signedness) v = integer_definition->value._unsigned; else v = (uint64_t) integer_definition->value._signed; fprintf(pos->fp, "0x%" PRIX64, v); break; }
When an integer is signed, it's casted to an unsigned 64-bit integer and, if the integer's size is 32-bit (or lower, that is) and its value is negative, it's printed with an unnecessary sign extension. For example, 0xeb3b39fd
makes Babeltrace print 0xFFFFFFFFEB3B39FD
.
Conversion specification %x
should be used when the integer's size is lesser than or equal to 32-bit, otherwise PRIX64
is fine. Same applies to %o
vs. PRIo64
.
Actions