From e81bab5250071e489f2577e33fccd5f7b8077fd2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 6 Oct 2024 13:58:20 -0400 Subject: Cleanly abort on allocation failure in atom tests Really just to avoid the common leaking realloc pattern recognized by static checkers. --- test/atom_test_utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/atom_test_utils.c b/test/atom_test_utils.c index e7d45d0..bffa2ea 100644 --- a/test/atom_test_utils.c +++ b/test/atom_test_utils.c @@ -1,12 +1,15 @@ // Copyright 2012-2018 David Robillard // SPDX-License-Identifier: ISC +#undef NDEBUG + #include "lv2/atom/atom.h" #include "lv2/atom/forge.h" #include "lv2/atom/util.h" #include "lv2/log/log.h" #include "lv2/urid/urid.h" +#include #include #include #include @@ -32,8 +35,11 @@ urid_map(LV2_URID_Map_Handle handle, const char* uri) } } - uris = (char**)realloc(uris, ++n_uris * sizeof(char*)); - uris[n_uris - 1] = copy_string(uri); + char** const new_uris = (char**)realloc(uris, (n_uris + 1) * sizeof(char*)); + assert(new_uris); + + uris = new_uris; + uris[n_uris++] = copy_string(uri); return n_uris; } -- cgit v1.2.1