diff options
Diffstat (limited to 'sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch')
| -rw-r--r-- | sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch b/sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch new file mode 100644 index 0000000..7fc8ee3 --- /dev/null +++ b/sutils/0004-battery.c-be-more-careful-with-the-printf-format.patch @@ -0,0 +1,46 @@ +From d3b11514c22943587e76def34c48655c78cd9610 Mon Sep 17 00:00:00 2001 +From: John Vogel <jvogel4@stny.rr.com> +Date: Mon, 9 Oct 2023 10:39:19 -0400 +Subject: [PATCH 4/4] battery.c: be more careful with the printf format + +--- + battery.c | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/battery.c b/battery.c +index 20307e5..0770619 100644 +--- a/battery.c ++++ b/battery.c +@@ -26,6 +26,7 @@ int put_infos(char *path, char *format) + char status[MAXLEN] = {0}; + int capacity = -1; + bool found_status = false, found_capacity = false; ++ bool print_status = false, print_capacity = false; + while (fgets(line, sizeof(line), bf) != NULL) { + char *key = strtok(line, TOKSEP); + if (key != NULL) { +@@ -43,12 +44,17 @@ int put_infos(char *path, char *format) + fprintf(stderr, "The battery information is missing.\n"); + return EXIT_FAILURE; + } else { +- if (strstr(format, "%s") == NULL) +- printf(format, capacity); +- else if (strstr(format, "%i") == NULL) ++ print_status = (strstr(format, "%s") == NULL) ? false : true; ++ print_capacity = (strstr(format, "%i") == NULL) ? false : true; ++ ++ if (print_status && print_capacity) ++ printf(format, status, capacity); ++ else if (print_status) + printf(format, status); ++ else if (print_capacity) ++ printf(format, capacity); + else +- printf(format, status, capacity); ++ return EXIT_FAILURE; + printf("\n"); + fflush(stdout); + } +-- +2.42.0 + |
