Fix zero copy sorting 67/282667/2
authorMateusz Majewski <m.majewski2@samsung.com>
Fri, 7 Oct 2022 13:20:01 +0000 (15:20 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Fri, 7 Oct 2022 13:42:53 +0000 (15:42 +0200)
Otherwise, the multiplication overflows since sec_sent_mono is 32 bit
and NSEC_PER_SEC is kinda big.

Change-Id: I1b4ce376bad39792929142feb7c3a05308188112

src/libdlogutil/fdi_zero_copy.c

index b6f58b2..e9d7f84 100644 (file)
@@ -273,7 +273,7 @@ static void sort_items_list(struct zlog_entry_list **items)
                        /* TODO: it would be good not to have to recalculate this.
                         * Perhaps have the item struct contain entry, next, timestamp?
                         * Maybe it's fine though, math is cheap. */
-                       const uint64_t timestamp64 = item->entry->sec_sent_mono * NSEC_PER_SEC + item->entry->nsec_sent_mono;
+                       const uint64_t timestamp64 = (uint64_t)item->entry->sec_sent_mono * NSEC_PER_SEC + item->entry->nsec_sent_mono;
 
                        int const bucket = (timestamp64 >> step) & 0xFF;
                        if (!begin[bucket])