Skip to contentSkip to conversation

Fix: ctf-text: signed base 8, 16 printout

PATCH Jérémie Galarneau 1 participant 1 message May 9, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Merged in master, stable-1.4 and stable-1.3.

Thanks!
Jérémie

Quoted 57 lines · Mathieu Desnoyers

Base 16 signed integer printout is buggy for 64-bit length: a shift of 64-bit is undefined.

Change printout of base 8 signed integer to match what is done for base 16.

---
 formats/ctf-text/types/integer.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
formats/ctf-text/types/integer.c +16 -7
index cc3a355..b4587c4 100644
@@ -101,10 +101,18 @@ 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 {
                        v = (uint64_t) integer_definition->value._signed;
+                       if (integer_declaration->len < 64) {
+                               /* Round length to the nearest 3-bit */
+                               uint8_t rounded_len =
+                                       integer_declaration->len + ((integer_declaration->len + 2) % 3);
+
+                               v &= ((uint64_t) 1 << rounded_len) - 1;
+                       }
+               }
 
                fprintf(pos->fp, "0%" PRIo64, v);
                break;
@@ -116,11 +124,13 @@ int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *def
                if (!integer_declaration->signedness) {
                        v = integer_definition->value._unsigned;
                } 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;
+                       if (integer_declaration->len < 64) {
+                               /* Round length to the nearest nibble */
+                               uint8_t rounded_len = ((integer_declaration->len + 3) & ~0x3);
+
+                               v &= ((uint64_t) 1 << rounded_len) - 1;
+                       }
                }
 
                fprintf(pos->fp, "0x%" PRIX64, v);
--

2.1.4

Signature · 7 lines
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev