Fix a type signedness mismatch 18/270218/1
authorMichal Bloch <m.bloch@samsung.com>
Wed, 26 Jan 2022 14:38:00 +0000 (15:38 +0100)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 26 Jan 2022 14:52:44 +0000 (15:52 +0100)
For size < 4, `char` was still cast to `unsigned` because of the earlier
operands, which also involved int promotion (so behaved the same as size == 4).

Change-Id: I7b9332bb20dd9d0035fc4607cb29a68cb82d0612
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
tests/kdbus/kdbus-util.c

index 85ea297..812e986 100644 (file)
@@ -797,10 +797,12 @@ wur int kdbus_msg_dump(const struct kdbus_msg *msg) {
                                break;
                        }
 
+                       /* FIXME: what if `size` is far more than 8? Can't the memfd have like, 500 size?
+                        * Originally this was simply %s/buf so showing only the first number sounds off */
                        kdbus_printf("  +%s (%llu bytes) fd=%i size=%llu filesize=%llu '0x%llx'\n",
                               enum_MSG(item->type), item->size, item->memfd.fd,
                               (unsigned long long)item->memfd.size,
-                              (unsigned long long)size, (unsigned long long)(size >= 8 ? *(unsigned long long *)buf : size >= 4 ? *(unsigned *)buf : *buf));
+                              (unsigned long long)size, (unsigned long long)(size >= 8 ? *(uint64_t *)buf : size >= 4 ? *(uint32_t *)buf : size >= 2 ? *(uint16_t *)buf : *(uint8_t *)buf));
                        munmap(buf, item->memfd.size);
                        break;
                }