Project

General

Profile

Actions

Bug #848

closed

ctf-text: negative signed 32-bit integers are incorrectly printed

Added by Philippe Proulx about 10 years ago. Updated about 10 years ago.

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 <>)

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 #1

Updated by Sébastien Boisvert about 10 years ago

inttypes.h also provides PRIx32 and PRIX32 as a portable alternative to %d.

Actions #2

Updated by Philippe Proulx about 10 years ago

Sébastien Boisvert wrote:

inttypes.h also provides PRIx32 and PRIX32 as a portable alternative to %d.

I guess you mean as a portable alternative to %x?

Actions #3

Updated by Jérémie Galarneau about 10 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset babeltrace|commit:43944bee2dea57d1626d3323ec5bc55e44bf2dae.

Actions

Also available in: Atom PDF