From c8b69b77ccb43c24e6399f756e803df002f91aaf Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Wed, 7 May 2025 18:46:55 +0100 Subject: [PATCH] libkmod: remove getdelim() buffer null check As per the manual getdelim(3): The buffer is null-terminated and ... Remove the local check and inline the function call. As a nice result, we no longer set the errno and the context of feof() is obvious. Reference: https://github.com/kmod-project/kmod/issues/244 Signed-off-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/346 Signed-off-by: Lucas De Marchi --- libkmod/libkmod-builtin.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/libkmod/libkmod-builtin.c b/libkmod/libkmod-builtin.c index 06ff4ab4..26c9e51c 100644 --- a/libkmod/libkmod-builtin.c +++ b/libkmod/libkmod-builtin.c @@ -62,19 +62,6 @@ static void kmod_builtin_info_release(struct kmod_builtin_info *info) fclose(info->fp); } -static ssize_t get_string(struct kmod_builtin_info *info) -{ - ssize_t len; - - len = getdelim(&info->buf, &info->bufsz, '\0', info->fp); - if (len > 0 && info->buf[len] != '\0') { - errno = EINVAL; - len = -1; - } - - return len; -} - static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, struct strbuf *buf) { @@ -84,11 +71,11 @@ static ssize_t get_strings(struct kmod_builtin_info *info, const char *modname, for (count = 0; count < INTPTR_MAX;) { char *dot, *line; - n = get_string(info); + n = getdelim(&info->buf, &info->bufsz, '\0', info->fp); if (n == -1) { if (!feof(info->fp)) { count = -errno; - ERR(info->ctx, "get_string: %m\n"); + ERR(info->ctx, "get_strings: %m\n"); } break; } -- 2.47.2