Skip to content

Commit

Permalink
Do not confuse the GCC 14 analyzer
Browse files Browse the repository at this point in the history
Although we assert size to be non-zero, this does not compute for
GCC's analyzer and thus causes a nasty diagnostic.

Doing the dumb thing™ and fail (even on intentional free) fixes this.
This also makes the initial assert kinda explicit in the code as
setting size==0 will be a surefire way to crash the program.
Now guaranteed in release mode too. ;-)
  • Loading branch information
BenBE committed Jul 11, 2024
1 parent db73229 commit ce9849c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion XUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void* xCalloc(size_t nmemb, size_t size) {

void* xRealloc(void* ptr, size_t size) {
assert(size > 0);
void* data = size ? realloc(ptr, size) : NULL; // deepcode ignore MemoryLeakOnRealloc: this goes to fail()
void* data = realloc(ptr, size);
if (!data) {
/* free'ing ptr here causes an indirect memory leak if pointers
* are held as part of an potential array referenced in ptr.
Expand Down

0 comments on commit ce9849c

Please sign in to comment.