Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit fb247d05c097d2db4d0f90ae0546d1af9618f829 Author: Raniconduh <clagv.randomgames@gmail.com> Date: Sun Jan 29 22:49:26 2023 +0000 fix segfault when setting cscroll string variables to boolean values diff --git a/include/var.h b/include/var.h index a35dcd4..bce0a51 100644 --- a/include/var.h +++ b/include/var.h @@ -36 +39 @@    #include <stdbool.h>   +#define VAR_FALSE ((void*)0) +#define VAR_TRUE ((void*)1) +  void var_init(void);  bool var_set(char *, void *);  void terminate_var(void); diff --git a/src/opts.c b/src/opts.c index 59bf77e..272860f 100644 --- a/src/opts.c +++ b/src/opts.c @@ -11816 +11812 @@ void parse_var(char * var) {   while (*val && *val != '=' && isspace(*val)) val++;     void * ptr_val = NULL; - bool bool_val = false; -   size_t vlen = strlen(val);     if (!strcmp(val, "true")) { - bool_val = true; - ptr_val = &bool_val; + ptr_val = VAR_TRUE;   } else if (!strcmp(val, "false")) { - bool_val = false; - ptr_val = &bool_val; + ptr_val = VAR_FALSE;   } else if (vlen > 2 && val[0] == '"' && val[vlen - 1] == '"') {   // empty strings not supported   val++; diff --git a/src/var.c b/src/var.c index b360e82..7344966 100644 --- a/src/var.c +++ b/src/var.c @@ -96 +97 @@  #include "hash.h"  #include "opts.h"  #include "main.h" +#include "var.h"  #include "dir.h"  #include "io.h"   @@ -186 +198 @@ static map * var_map = NULL;    // must be 6 characters long  static uint32_t hextorgb(char * hex) { + if (hex == VAR_FALSE || hex == VAR_TRUE) return COLOR_DEFAULT; +   char * p = hex;   if (*p == '#') p++;   @@ -4430 +4728 @@ static uint32_t hextorgb(char * hex) {   b = (float)(dec & 0xFF) / 255.0 * 1000;     return RGB(r, g, b); - - return 0;  }      // void * p -> bool p  static void set_icons(void * p) { - show_icons = *(bool*)p; + show_icons = (bool)p;  }      static void set_color_f(void * p) { - color = *(bool*)p; + color = (bool)p;   set_color();  }      static void set_long(void * p) { - p_long = *(bool*)p; + p_long = (bool)p;  }      static void set_dots(void * p) { - show_dot_files = *(bool*)p; + show_dot_files = (bool)p;     free_dir_entries();   list_dir(cwd); @@ -1386 +1398 @@ static void set_archive(void * p) {      static void set_opener(void * p) { + if (p == VAR_FALSE || p == VAR_TRUE) return; +   char * s = (char*)p;   if (s && *s) {   size_t l = strlen(s);