tests: cast pid_t and struct timeval fields before printing

The exact type behind these might depend on the architecture. For
instance, on ARMv7, struct timeval fields are long long int instead
of long int:

    FAILED: tests/libtest-runner.a.p/test-compositor.c.o
    cc -Itests/libtest-runner.a.p -Itests -I../tests -I. -I.. -Isrc -I../src -fdiagnostics-color=always -fsanitize=address,undefined -fno-omit-frame-pointer -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c99 -O0 -g -D_POSIX_C_SOURCE=200809L -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -fvisibility=hidden -fPIC -pthread -MD -MQ tests/libtest-runner.a.p/test-compositor.c.o -MF tests/libtest-runner.a.p/test-compositor.c.o.d -o tests/libtest-runner.a.p/test-compositor.c.o -c ../tests/test-compositor.c
    ../tests/test-compositor.c: In function 'get_socket_name':
    ../tests/test-compositor.c:95:60: error: format '%ld' expects argument of type 'long int', but argument 5 has type '__time64_t' {aka 'long long int'} [-Werror=format=]
       95 |         snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld",
          |                                                          ~~^
          |                                                            |
          |                                                            long int
          |                                                          %lld
       96 |                  getpid(), tv.tv_sec, tv.tv_usec);
          |                            ~~~~~~~~~
          |                              |
          |                              __time64_t {aka long long int}
    ../tests/test-compositor.c:95:63: error: format '%ld' expects argument of type 'long int', but argument 6 has type '__suseconds64_t' {aka 'long long int'} [-Werror=format=]
       95 |         snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld",
          |                                                             ~~^
          |                                                               |
          |                                                               long int
          |                                                             %lld
       96 |                  getpid(), tv.tv_sec, tv.tv_usec);
          |                                       ~~~~~~~~~~
          |                                         |
          |                                         __suseconds64_t {aka long long int}

Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
Simon Ser 2025-12-27 12:41:06 +01:00 committed by Daniel Stone
parent f72e3fae4a
commit 8c0947892b

View file

@ -92,8 +92,8 @@ get_socket_name(void)
static char retval[64]; static char retval[64];
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld", snprintf(retval, sizeof retval, "wayland-test-%d-%lld%lld",
getpid(), tv.tv_sec, tv.tv_usec); (int) getpid(), (long long int) tv.tv_sec, (long long int) tv.tv_usec);
return retval; return retval;
} }