From df249f1c35ee451bd839a444ed18411426fe2af1 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 23 Apr 2025 16:51:50 +0200 Subject: [PATCH] fix: checking incorrect memory adresses also updated assertions and remove some in place of attributes --- src/game/opts.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/game/opts.c b/src/game/opts.c index 7c66a78..c653de4 100644 --- a/src/game/opts.c +++ b/src/game/opts.c @@ -41,17 +41,14 @@ struct proc_buf_dat { }; /* use malloc to append src to the end of dest. - if dest == NULL, memory is allocated, otherwise it is reallocated. + if *dest == NULL, memory is allocated, otherwise it is reallocated. returns 0 upon success, 1 upon failure. */ -static inline int str_put(char* restrict* restrict dest, size_t dest_len, char const* restrict src, size_t src_len) { - assert(dest); - assert(src); - if (!dest) { +__attribute__((nonnull(1, 3))) static inline int str_put(char* restrict* restrict dest, size_t dest_len, char const* restrict src, size_t src_len) { + if (!*dest) { *dest = malloc(src_len + 1); if (!*dest) return 1; } else { - assert(*dest); - assert(src_len > dest_len); + assert(src_len > dest_len); // sanity check void* ptr = realloc(*dest, src_len + 1); if (!ptr) return 1; *dest = ptr;