]> granicus.if.org Git - graphviz/commitdiff
colxlate canoncolor: operate on 'char' instead of 'unsigned char'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 17 Sep 2021 03:35:44 +0000 (20:35 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Sep 2021 23:20:33 +0000 (16:20 -0700)
It is unclear to me why this code was using unsigned char variables. This was
unnecessary, induced noisy casting and caused build warnings. This also changes
the `orig` parameter to a const pointer as the function does not modify the
pointed to data.

cmd/tools/colxlate.c

index f1d9fbefdc9fc310eab46c585e4f33c0356c7b62..4c40ac4b18b5d337618750efafe1a5cce1bd61d9 100644 (file)
@@ -24,15 +24,15 @@ typedef struct hsbcolor_t {
 #ifndef NOCOLORNAMES
 #include "colortbl.h"
 
-static unsigned char *canoncolor(char *orig, unsigned char *out)
+static char *canoncolor(const char *orig, char *out)
 {
-    unsigned char c;
-    unsigned char *p = out;
-    while ((c = *(unsigned char *) orig++)) {
+    char c;
+    char *p = out;
+    while ((c = *orig++)) {
        if (!isalnum(c))
            continue;
        if (isupper(c))
-           c = tolower(c);
+           c = (char)tolower(c);
        *p++ = c;
     }
     *p = '\0';
@@ -49,12 +49,12 @@ static int colorcmpf(const void *a0, const void *a1)
 char *colorxlate(char *str, char *buf)
 {
     static hsbcolor_t *last;
-    unsigned char canon[128];
+    char canon[128];
     char *p;
     hsbcolor_t fake;
 
     if (last == NULL || strcmp(last->name, str)) {
-       fake.name = (char *) canoncolor(str, canon);
+       fake.name = canoncolor(str, canon);
        last = bsearch(&fake, color_lib, sizeof(color_lib) / sizeof(hsbcolor_t),
                       sizeof(fake), colorcmpf);
     }