fix: remove dead NULL checks after g_malloc/g_new in gerb_file.c#353
Merged
spe-ciellt merged 1 commit intogerbv:developfrom Mar 5, 2026
Merged
fix: remove dead NULL checks after g_malloc/g_new in gerb_file.c#353spe-ciellt merged 1 commit intogerbv:developfrom
spe-ciellt merged 1 commit intogerbv:developfrom
Conversation
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
This was referenced Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GLib's
g_malloc(),g_new(), andg_build_filename()abort the process on allocation failure and never returnNULL. TheNULL-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():if (fd == NULL) return NULLafterg_new()if (buf == NULL) { munmap; fclose; g_free; return NULL }afterg_malloc()gerb_fgetstring():if (newstr == NULL) return NULLafterg_malloc()gerb_find_file():if (env_name == NULL) return NULLafterg_malloc()if (curr_path == NULL) return NULLafterg_malloc()if (complete_path == NULL) return NULLafterg_build_filename()No functional change — all removed paths were unreachable.
Closes #348