Fix: undefined bit shift operation when printing octal numbers
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 30 May 2016 18:39:27 +0000 (14:39 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 30 May 2016 18:54:41 +0000 (14:54 -0400)
Reported by Coverity as:
CID 1355338 (#1 of 1): Bad bit shift operation (BAD_SHIFT)

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf-text/types/integer.c

index ca0e5e6020b3ed0f3002ef410934bf196bb0b493..c08aa4bc24412b3573fd27af9b147ae703adb9dd 100644 (file)
@@ -106,11 +106,12 @@ int ctf_text_integer_write(struct bt_stream_pos *ppos, struct bt_definition *def
                } 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);
+                               size_t len = integer_declaration->len;
+                               size_t rounded_len;
 
+                               assert(len != 0);
+                               /* Round length to the nearest 3-bit */
+                               rounded_len = (((len - 1) / 3) + 1) * 3;
                                v &= ((uint64_t) 1 << rounded_len) - 1;
                        }
                }
This page took 0.033518 seconds and 4 git commands to generate.