[PATCH 0/2] MR868: ntdll, libwine: Avoid comparing the result of pointer arithmetic to zero.
It's not exactly clear to me why gcc warns about this (and it's hard to find reference for this specific flavor of -Waddress), but my understanding is that arithmetic on well-defined pointers will never yield NULL. Of course, we are not dealing with well-defined pointers here, but fortunately gcc does not complain if we cast to intptr_t first. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/868
From: Zebediah Figura <zfigura(a)codeweavers.com> gcc warns about this: ../wine/dlls/ntdll/unix/virtual.c: In function ‘mmap_add_reserved_area’: ../wine/dlls/ntdll/unix/virtual.c:241:9: error: the comparison will always evaluate as ‘true’ for the pointer operand in ‘(char *)addr + (sizetype)size’ must not be NULL [-Werror=address] 241 | if (!((char *)addr + size)) size--; /* avoid wrap-around */ | ^ --- dlls/ntdll/unix/virtual.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 96a5e095d16..e0aa410373e 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -238,7 +238,7 @@ static void mmap_add_reserved_area( void *addr, SIZE_T size ) struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + if (!((intptr_t)addr + size)) size--; /* avoid wrap-around */ LIST_FOR_EACH( ptr, &reserved_areas ) { @@ -287,7 +287,7 @@ static void mmap_remove_reserved_area( void *addr, SIZE_T size ) struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + if (!((intptr_t)addr + size)) size--; /* avoid wrap-around */ ptr = list_head( &reserved_areas ); /* find the first area covering address */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/868
From: Zebediah Figura <zfigura(a)codeweavers.com> gcc warns about this: ../wine/libs/wine/mmap.c: In function ‘wine_mmap_add_reserved_area_obsolete’: ../wine/libs/wine/mmap.c:504:9: error: the comparison will always evaluate as ‘true’ for the pointer operand in ‘(char *)addr + (sizetype)size’ must not be NULL [-Werror=address] 504 | if (!((char *)addr + size)) size--; /* avoid wrap-around */ | ^ --- libs/wine/mmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/wine/mmap.c b/libs/wine/mmap.c index ad51153d039..1f8ae3c7720 100644 --- a/libs/wine/mmap.c +++ b/libs/wine/mmap.c @@ -501,7 +501,7 @@ void wine_mmap_add_reserved_area_obsolete( void *addr, size_t size ) struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + if (!((intptr_t)addr + size)) size--; /* avoid wrap-around */ LIST_FOR_EACH( ptr, &reserved_areas ) { @@ -560,7 +560,7 @@ void wine_mmap_remove_reserved_area_obsolete( void *addr, size_t size, int unmap struct reserved_area *area; struct list *ptr; - if (!((char *)addr + size)) size--; /* avoid wrap-around */ + if (!((intptr_t)addr + size)) size--; /* avoid wrap-around */ ptr = list_head( &reserved_areas ); /* find the first area covering address */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/868
participants (2)
-
Zebediah Figura -
Zebediah Figura (@zfigura)