Skip to content

fix: remove dead NULL checks after g_malloc/g_new in gerb_file.c#353

Merged
spe-ciellt merged 1 commit intogerbv:developfrom
SourceParts:fix/dead-null-checks
Mar 5, 2026
Merged

fix: remove dead NULL checks after g_malloc/g_new in gerb_file.c#353
spe-ciellt merged 1 commit intogerbv:developfrom
SourceParts:fix/dead-null-checks

Conversation

@rampageservices
Copy link
Copy Markdown
Contributor

GLib's g_malloc(), g_new(), and g_build_filename() abort the process on allocation failure and never return NULL. The NULL-check branches after these calls are dead code — unreachable under any circumstances.

This removes the dead branches and adds comments documenting the abort-on-OOM behavior so future contributors don't re-add them.

Changes

gerb_fopen():

  • Remove if (fd == NULL) return NULL after g_new()
  • Remove if (buf == NULL) { munmap; fclose; g_free; return NULL } after g_malloc()

gerb_fgetstring():

  • Remove if (newstr == NULL) return NULL after g_malloc()

gerb_find_file():

  • Remove if (env_name == NULL) return NULL after g_malloc()
  • Remove if (curr_path == NULL) return NULL after g_malloc()
  • Remove if (complete_path == NULL) return NULL after g_build_filename()

No functional change — all removed paths were unreachable.

Closes #348

GLib's g_malloc() and g_new() abort the process on allocation failure
and never return NULL. Remove the unreachable NULL-check branches and
add comments documenting the abort-on-OOM behavior.

Affected functions:
- gerb_fopen(): g_new() and g_malloc() NULL checks
- gerb_fgetstring(): g_malloc() NULL check
- gerb_find_file(): g_malloc() and g_build_filename() NULL checks

Closes gerbv#348
@spe-ciellt spe-ciellt added the pr-fixes Fixes that fixes fixes. Should refer to the original fix, not listed as fix in the release notes. label Mar 5, 2026
@spe-ciellt spe-ciellt merged commit 2b944b0 into gerbv:develop Mar 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fixes Fixes that fixes fixes. Should refer to the original fix, not listed as fix in the release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

g_malloc() NULL path is dead code — saved_errno there is never reached

2 participants