From 5c2f02b2ea5e131deec105a48a3b6a16d4e46633 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Sat, 16 Aug 2025 15:45:05 +0100 Subject: [PATCH] test/zdtm/static/maps12: fix pointer-to-int cast The `offset` argument to `mmap()` was computed with a direct cast from pointer to `off_t`: `(off_t)addr_hint - (off_t)map_base` This causes a build failure when compiling since pointers and `off_t` may differ in size on some platforms. maps12.c: In function 'mmap_pages': maps12.c:114:50: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] 114 | filemap ? fd : -1, filemap ? ((off_t)addr_hint - (off_t)map_base) : 0); | ^ maps12.c:114:69: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast] 114 | filemap ? fd : -1, filemap ? ((off_t)addr_hint - (off_t)map_base) : 0); The fix in this patch is to cast both pointers to `intptr_t`, perform the subtraction in that type, and then cast the result back to `off_t`. Signed-off-by: Radostin Stoyanov --- test/zdtm/static/maps12.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/zdtm/static/maps12.c b/test/zdtm/static/maps12.c index b645595be..f0d6c2381 100644 --- a/test/zdtm/static/maps12.c +++ b/test/zdtm/static/maps12.c @@ -111,7 +111,8 @@ static inline void *mmap_pages(void *addr_hint, unsigned int count, bool filemap map = mmap(addr_hint, count * PAGE_SIZE, PROT_WRITE | PROT_READ, MAP_PRIVATE | (filemap ? 0 : MAP_ANONYMOUS) | (addr_hint ? MAP_FIXED : 0), - filemap ? fd : -1, filemap ? ((off_t)addr_hint - (off_t)map_base) : 0); + filemap ? fd : -1, + filemap ? (off_t)((intptr_t)addr_hint - (intptr_t)map_base) : 0); if (map == MAP_FAILED || (addr_hint && (map != addr_hint))) return MAP_FAILED;