logging: Fix timestamp 32bit integer overflow

We are specifically requesting wall time for the logging output, but
using 32 bits for micro-seconds does overflow, leaving us with an
arbitrary integer.

Signed-off-by: Robert Griebl <robert.griebl@qt.io>
This commit is contained in:
Robert Griebl 2025-05-13 15:03:16 +02:00
parent 6137c8c213
commit b703d87bd8
2 changed files with 7 additions and 8 deletions

View file

@ -1495,7 +1495,7 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
struct argument_details arg;
const char *signature = closure->message->signature;
struct timespec tp;
unsigned int time;
uint64_t time;
uint32_t nval;
FILE *f;
char *buffer;
@ -1506,10 +1506,9 @@ wl_closure_print(struct wl_closure *closure, struct wl_object *target,
return;
clock_gettime(CLOCK_REALTIME, &tp);
time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
fprintf(f, "[%7u.%03u] ", time / 1000, time % 1000);
time = (tp.tv_sec * 1000000LL) + (tp.tv_nsec / 1000);
fprintf(f, "[%7" PRIu64 ".%03u] ", time / 1000, (unsigned int) (time % 1000));
if (queue_name)
fprintf(f, "{%s} ", queue_name);

View file

@ -1557,7 +1557,7 @@ queue_event(struct wl_display *display, int len)
const struct wl_message *message;
struct wl_event_queue *queue;
struct timespec tp;
unsigned int time;
uint64_t time;
int num_zombie_fds;
wl_connection_copy(display->connection, p, sizeof p);
@ -1577,11 +1577,11 @@ queue_event(struct wl_display *display, int len)
if (debug_client) {
clock_gettime(CLOCK_REALTIME, &tp);
time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000);
time = (tp.tv_sec * 1000000LL) + (tp.tv_nsec / 1000);
fprintf(stderr, "[%7u.%03u] discarded [%s]#%d.[event %d]"
fprintf(stderr, "[%7" PRIu64 ".%03u] discarded [%s]#%d.[event %d]"
"(%d fd, %d byte)\n",
time / 1000, time % 1000,
time / 1000, (unsigned int) (time % 1000),
zombie ? "zombie" : "unknown",
id, opcode,
num_zombie_fds, size);