X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fclient%2Farray_append.c;h=52bcf97f2599b0a9136c122a78ec672ed5e62812;hb=20da835cb5f85fc3416caef6e70bd74711bd75d0;hp=37fde0ed90cdbde8097ce44839cbc4215b5aca53;hpb=1cb57a35a3b3cc4ec8870531ca254a655c0bdda2;p=plomrogue diff --git a/src/client/array_append.c b/src/client/array_append.c index 37fde0e..52bcf97 100644 --- a/src/client/array_append.c +++ b/src/client/array_append.c @@ -1,10 +1,16 @@ -/* src/client/array_append.c */ +/* src/client/array_append.c + * + * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3 + * or any later version. For details on its copyright, license, and warranties, + * see the file NOTICE in the root directory of the PlomRogue source package. + */ #include "array_append.h" #include /* size_t */ -#include /* uint32_t */ +#include /* uint32_t, UINT32_MAX */ #include /* free() */ #include /* memcpy() */ +#include "../common/rexit.h" /* exit_trouble() */ #include "../common/try_malloc.h" /* try_malloc() */ @@ -12,12 +18,12 @@ extern void array_append(uint32_t old_n, size_t region_size, void * new_region, void ** ptr_old_array) { + exit_trouble(UINT32_MAX<(old_n+1)*region_size, __func__, "too large sizes"); uint32_t old_size = old_n * region_size; uint32_t new_size = old_size + region_size; char * new_array = try_malloc(new_size, __func__); memcpy(new_array, * ptr_old_array, old_size); memcpy(new_array + (old_n * region_size), new_region, region_size); free(* ptr_old_array); - * ptr_old_array = new_array; + *ptr_old_array = new_array; } -