]> Sergey Matveev's repositories - nnn.git/commitdiff
Detect odd hex symbols in NNN_COLORS
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 3 Aug 2020 19:12:58 +0000 (00:42 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 3 Aug 2020 19:12:58 +0000 (00:42 +0530)
src/nnn.c

index e63d706be682687991c05fd3daa33cf04dac752c..1349f361e1d5f4aa5ce94196d3412515cfa436e9 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1589,7 +1589,6 @@ static bool initcurses(void *oldmask)
 
        if (colors || !getenv("NO_COLOR")) {
                uint *pcode;
-               char ch;
                bool ext = FALSE;
 
                start_color();
@@ -1622,16 +1621,17 @@ static bool initcurses(void *oldmask)
 
                        if (colors && *colors) {
                                if (ext) {
-                                       ch = *colors;
-                                       if (*++colors) {
-                                               *pcode = (16 * xchartohex(ch)) + xchartohex(*colors);
-                                               ++colors;
-                                       } else
-                                               *pcode = xchartohex(ch);
-                               } else {
+                                       *pcode = xchartohex(*colors) << 4;
+                                       if (*++colors)
+                                               *pcode += xchartohex(*colors);
+                                       else { /* Each color code must be 2 hex symbols */
+                                               exitcurses();
+                                               fprintf(stderr, "NNN_COLORS!\n");
+                                               return FALSE;
+                                       }
+                               } else
                                        *pcode = (*colors < '0' || *colors > '7') ? 4 : *colors - '0';
-                                       ++colors;
-                               }
+                               ++colors;
                        } else
                                *pcode = 4;