From 6cf5e8f9324095f2226ee666eee9090fbc6da287 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 27 May 2022 16:54:49 +0200 Subject: [PATCH] cursor: use getline instead of fgets This avoids storing 8KiB on the stack, and removes the line length limit. Signed-off-by: Simon Ser --- cursor/xcursor.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cursor/xcursor.c b/cursor/xcursor.c index 1974802e..315fe00a 100644 --- a/cursor/xcursor.c +++ b/cursor/xcursor.c @@ -698,7 +698,8 @@ xcursor_sep(char c) static char * xcursor_theme_inherits(const char *full) { - char line[8192]; + char *line = NULL; + size_t line_size = 0; char *result = NULL; FILE *f; @@ -709,7 +710,7 @@ xcursor_theme_inherits(const char *full) if (!f) return NULL; - while (fgets(line, sizeof(line), f)) { + while (getline(&line, &line_size, f) >= 0) { if (strncmp(line, "Inherits", 8)) continue; @@ -743,6 +744,8 @@ xcursor_theme_inherits(const char *full) } fclose(f); + free(line); + return result; }