Fix: respect signed integers' length when printing in hex base
[babeltrace.git] / formats / ctf-text / types / integer.c
index 34df4fc9fca49190f7c55c0d26440563ed18f5d8..cc3a3551b2bc31074c4fd532c6414b456868db44 100644 (file)
@@ -113,10 +113,15 @@ int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *def
        {
                uint64_t v;
 
-               if (!integer_declaration->signedness)
+               if (!integer_declaration->signedness) {
                        v = integer_definition->value._unsigned;
-               else
+               } else {
+                       /* Round length to the nearest nibble */
+                       uint8_t rounded_len = ((integer_declaration->len + 3) & ~0x3);
+
                        v = (uint64_t) integer_definition->value._signed;
+                       v &= ((uint64_t) 1 << rounded_len) - 1;
+               }
 
                fprintf(pos->fp, "0x%" PRIX64, v);
                break;
This page took 0.030828 seconds and 4 git commands to generate.