#include <stdarg.h>
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
static void mmap_add_reserved_area( void *addr, SIZE_T size )
{
+ SIZE_T max_size = SIZE_MAX - (SIZE_T)addr;
struct reserved_area *area;
struct list *ptr;
- if (!((char *)addr + size)) size--; /* avoid wrap-around */
+ _Static_assert(sizeof(SIZE_MAX) == sizeof(SIZE_T), "SIZE_MAX and SIZE_T are not the same size");
+
+ if (size > max_size) size = max_size; /* avoid wrap-around */
LIST_FOR_EACH( ptr, &reserved_areas )
{
static void mmap_remove_reserved_area( void *addr, SIZE_T size )
{
+ SIZE_T max_size = SIZE_MAX - (SIZE_T)addr;
struct reserved_area *area;
struct list *ptr;
- if (!((char *)addr + size)) size--; /* avoid wrap-around */
+ _Static_assert(sizeof(SIZE_MAX) == sizeof(SIZE_T), "SIZE_MAX and SIZE_T are not the same size");
+
+ if (size > max_size) size = max_size; /* avoid wrap-around */
ptr = list_head( &reserved_areas );
/* find the first area covering address */
*/
void wine_mmap_add_reserved_area_obsolete( void *addr, size_t size )
{
+ size_t max_size = SIZE_MAX - (size_t)addr;
struct reserved_area *area;
struct list *ptr;
- if (!((char *)addr + size)) size--; /* avoid wrap-around */
+ _Static_assert(sizeof(SIZE_MAX) == sizeof(size_t), "SIZE_MAX and SIZE_T are not the same size");
+
+ if (size > max_size) size = max_size; /* avoid wrap-around */
LIST_FOR_EACH( ptr, &reserved_areas )
{
*/
void wine_mmap_remove_reserved_area_obsolete( void *addr, size_t size, int unmap )
{
+ size_t max_size = SIZE_MAX - (size_t)addr;
struct reserved_area *area;
struct list *ptr;
- if (!((char *)addr + size)) size--; /* avoid wrap-around */
+ _Static_assert(sizeof(SIZE_MAX) == sizeof(size_t), "SIZE_MAX and SIZE_T are not the same size");
+
+ if (size > max_size) size = max_size; /* avoid wrap-around */
ptr = list_head( &reserved_areas );
/* find the first area covering address */