g_malloc() NULL path is dead code — saved_errno there is never reached
GLib's g_malloc() is documented to never return NULL: on allocation failure it calls g_error() (which terminates the process). The if (buf == NULL) block at line 116 is therefore dead code, and the saved_errno additions there:
char *buf = (char *)g_malloc(fd->datalen + 1);
if (buf == NULL) { /* ← can never be true */
int saved_errno = errno;
munmap(fd->data, fd->datalen);
fclose(fd->fd);
g_free(fd);
errno = saved_errno;
return NULL;
}
are unreachable. The PR did not introduce the dead if (buf == NULL) guard (it's pre-existing), and applying the idiom uniformly is defensively correct, so this is not a blocker. However, it's worth a comment that g_malloc is abort-on-OOM in GLib.
Similarly, g_new() at the top of the function (fd = g_new(gerb_file_t, 1)) never returns NULL, making the if (fd == NULL) return NULL check at line 64 also unreachable. Same pre-existing issue, not introduced here.
Considered minor and save for future updates.
Originally posted by @spe-ciellt in #319 (comment)
g_malloc()NULL path is dead code —saved_errnothere is never reachedGLib's
g_malloc()is documented to never return NULL: on allocation failure it callsg_error()(which terminates the process). Theif (buf == NULL)block at line 116 is therefore dead code, and thesaved_errnoadditions there:are unreachable. The PR did not introduce the dead
if (buf == NULL)guard (it's pre-existing), and applying the idiom uniformly is defensively correct, so this is not a blocker. However, it's worth a comment thatg_mallocis abort-on-OOM in GLib.Similarly,
g_new()at the top of the function (fd = g_new(gerb_file_t, 1)) never returns NULL, making theif (fd == NULL) return NULLcheck at line 64 also unreachable. Same pre-existing issue, not introduced here.Considered minor and save for future updates.
Originally posted by @spe-ciellt in #319 (comment)