]> git.refcnt.org Git - colorize.git/blobdiff - colorize.c
Cast argument to unsigned char when invoking is*()
[colorize.git] / colorize.c
index 2b628d369f338fe4d4a30a894f3c2289e2d081b8..88de5fbae3bef57398e0b8fd9df3ada996fa7f0a 100644 (file)
@@ -383,8 +383,12 @@ main (int argc, char **argv)
 
 #if DEBUG
     log = open_file (DEBUG_FILE, "w");
-    STACK_FILE (log);
     print_tstamp (log);
+    /* We're in debugging mode, hence we can't invoke STACK_FILE()
+       prior to print_tstamp(), because both cause text to be written
+       to the same logfile which is expected to have the timestamp
+       first.  */
+    STACK_FILE (log);
 #endif
 
     attr[0] = '\0';
@@ -451,7 +455,7 @@ main (int argc, char **argv)
       {
         if (arg_cnt == 0 || arg_cnt > 2)
           {
-            vfprintf_diag ("%u arguments provided, expected 1-2 arguments or clean option", arg_cnt);
+            vfprintf_diag ("%u arguments provided, expected 1-2 arguments or --clean[-all]", arg_cnt);
             print_hint ();
             exit (EXIT_FAILURE);
           }
@@ -609,10 +613,10 @@ process_opt_attr (const char *p, const bool is_opt)
     while (*p)
       {
         const char *s;
-        if (!isalnum (*p))
+        if (!isalnum ((unsigned char)*p))
           vfprintf_fail ("%s must be provided a string", desc_type[DESC_TYPE]);
         s = p;
-        while (isalnum (*p))
+        while (isalnum ((unsigned char)*p))
           p++;
         if (*p != '\0' && *p != ',')
           vfprintf_fail ("%s must have strings separated by ,", desc_type[DESC_TYPE]);
@@ -747,7 +751,7 @@ parse_conf (const char *conf_file, struct conf *config)
 /* NAME PARSING (end) */
 /* NAME VALIDATION (start) */
         for (p = opt; *p; p++)
-          if (!isalnum (*p) && *p != '-')
+          if (!isalnum ((unsigned char)*p) && *p != '-')
             vfprintf_fail (formats[FMT_CONF], conf_file, opt, "cannot be made of non-option characters");
 /* NAME VALIDATION (end) */
 /* VALUE PARSING (start) */
@@ -969,8 +973,9 @@ cleanup (void)
                   fclose (var->ptr);
                   break;
                 case IS_UNUSED:
-                default:
                   break;
+                default: /* never reached */
+                  ABORT_TRACE ();
               }
           }
         free_null (vars_list);
@@ -1201,17 +1206,17 @@ gather_color_names (const char *color_string, char *attr, struct color_name **co
         assert (p != NULL);
 
         for (ch = color; *ch; ch++)
-          if (!isalpha (*ch))
+          if (!isalpha ((unsigned char)*ch))
             vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be made of non-alphabetic characters");
 
         for (ch = color + 1; *ch; ch++)
-          if (!islower (*ch))
+          if (!islower ((unsigned char)*ch))
             vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be in mixed lower/upper case");
 
         if (streq (color, "None"))
           vfprintf_fail (formats[FMT_COLOR], tables[index].desc, color, "cannot be bold");
 
-        if (isupper (*color))
+        if (isupper ((unsigned char)*color))
           {
             switch (index)
               {
@@ -1599,10 +1604,10 @@ gather_esc_offsets (const char *p, const char **start, const char **end)
             do {
               check_values = false;
               iter++;
-              if (!isdigit (*p))
+              if (!isdigit ((unsigned char)*p))
                 break;
               digit = p;
-              while (isdigit (*p))
+              while (isdigit ((unsigned char)*p))
                 p++;
               if (p - digit > 2)
                 break;
@@ -1635,7 +1640,7 @@ gather_esc_offsets (const char *p, const char **start, const char **end)
 static bool
 validate_esc_clean_all (const char **p)
 {
-    while (isdigit (**p) || **p == ';')
+    while (isdigit ((unsigned char)**p) || **p == ';')
       (*p)++;
     return (**p == 'm');
 }
@@ -1926,7 +1931,8 @@ release (struct var_list *list, unsigned int stacked, void **ptr)
     for (i = 0; i < stacked; i++)
       {
         struct var_list *var = &list[i];
-        if (var->ptr == *ptr)
+        if (var->type != IS_UNUSED
+         && var->ptr == *ptr)
           {
             switch (var->type)
               {
@@ -1936,9 +1942,9 @@ release (struct var_list *list, unsigned int stacked, void **ptr)
                 case IS_FILE:
                   fclose (*ptr);
                   break;
-                default:
-                  break;
-             }
+                default: /* never reached */
+                  ABORT_TRACE ();
+              }
             *ptr = NULL;
             var->ptr  = NULL;
             var->type = IS_UNUSED;