From f1ef095a9cc9997016b95756198ecb9212d0b3d0 Mon Sep 17 00:00:00 2001 From: Joshix Date: Sun, 3 Oct 2021 12:36:08 +0200 Subject: [PATCH 1/2] fix replacing ignorecase with multiple things to replace --- uwufetch.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index f20fc32..bc62f6f 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) for (int i = 0; gpu_model[i][0]; i++) { - uwu_hw(gpu_model[i]); + uwu_hw(gpu_model[i]); } uwu_hw(cpu_model); uwu_hw(host_model); @@ -708,11 +708,12 @@ replace("Hello World!", "World", "everyone") */ void replace(char *original, char *search, char *replacer) { - char buffer[1024]; char *ch; if (!(ch = strstr(original, search))) return; + char buffer[1024]; + strncpy(buffer, original, ch - original); buffer[ch - original] = 0; sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); @@ -724,18 +725,20 @@ void replace(char *original, char *search, char *replacer) void replace_ignorecase(char *original, char *search, char *replacer) { - char buffer[1024]; char *ch; if (!(ch = strcasestr(original, search))) return; + char buffer[1024]; + strncpy(buffer, original, ch - original); buffer[ch - original] = 0; sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); original[0] = 0; strcpy(original, buffer); - return replace(original, search, replacer); + replace(original, search, replacer); + return replace_ignorecase(original, search, replacer); } void print_ascii() From 047dbb49f990c3e66cd6eff7c0e143868c6c7e0c Mon Sep 17 00:00:00 2001 From: TheDarkBug Date: Sun, 3 Oct 2021 13:51:05 +0200 Subject: [PATCH 2/2] Fixed recursion segfault (on my system works) --- uwufetch.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index bc62f6f..068d48c 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -188,9 +188,10 @@ void parse_config() // opening and reading the config file FILE *config; - if (config_directory == NULL) + if (config_directory == NULL) { if (homedir != NULL) config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); + } else config = fopen(config_directory, "r"); if (config == NULL) @@ -738,7 +739,7 @@ void replace_ignorecase(char *original, char *search, char *replacer) original[0] = 0; strcpy(original, buffer); replace(original, search, replacer); - return replace_ignorecase(original, search, replacer); + return replace(original, search, replacer); } void print_ascii()