]> granicus.if.org Git - nethack/commitdiff
error on parse_condition pr #680
authornhmall <nhmall@nethack.org>
Thu, 10 Feb 2022 23:18:25 +0000 (18:18 -0500)
committernhmall <nhmall@nethack.org>
Thu, 10 Feb 2022 23:18:25 +0000 (18:18 -0500)
The  while(s[sidx]) { ... was acting as while(1), but the
loop body contained appropriate checks and returns to
function correctly.

Fixes #680

src/botl.c

index 32f06fdecd2dab1593aebb9d5cf3c6059668d02d..f5314647c6ddc87da97e30f972dcbaf8ee2e8d65 100644 (file)
@@ -2410,7 +2410,7 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile)
         return parse_condition(s, sidx);
 
     ++sidx;
-    while (s[sidx]) {
+    while (s[sidx][0]) {
         char buf[BUFSZ], **subfields;
         int sf = 0;     /* subfield count */
         int kidx;
@@ -2419,11 +2419,11 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile)
         percent = numeric = always = FALSE;
         down = up = changed = FALSE;
         gt = ge = eq = le = lt = txtval = FALSE;
-
-        /* threshold value */
+#if 0
+        /* threshold value - return on empty string */
         if (!s[sidx][0])
             return TRUE;
-
+#endif
         memset((genericptr_t) &hilite, 0, sizeof (struct hilite_s));
         hilite.set = FALSE; /* mark it "unset" */
         hilite.fld = fld;
@@ -2600,8 +2600,10 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile)
             else {
                 int c = match_str2clr(subfields[i]);
 
-                if (c >= CLR_MAX || coloridx != -1)
+                if (c >= CLR_MAX || coloridx != -1) {
+                    config_error_add("bad color '%d %d'", c, coloridx);
                     return FALSE;
+                }
                 coloridx = c;
             }
         }
@@ -2640,7 +2642,7 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile)
         sidx++;
     }
 
-    return TRUE;
+    return (successes > 0);
 }
 #endif /* STATUS_HILITES */
 
@@ -2776,7 +2778,7 @@ parse_condition(char (*s)[QBUFSZ], int sidx)
     int coloridx = NO_COLOR;
     char *tmp, *how;
     unsigned long conditions_bitmask = 0UL;
-    boolean success = FALSE;
+    boolean result = FALSE;
 
     if (!s)
         return FALSE;
@@ -2794,17 +2796,15 @@ parse_condition(char (*s)[QBUFSZ], int sidx)
      */
 
     sidx++;
-    while(s[sidx]) {
+    if (!s[sidx][0]) {
+        config_error_add("Missing condition(s)");
+        return FALSE;
+    }
+    while (s[sidx][0]) {
         int sf = 0;     /* subfield count */
         char buf[BUFSZ], **subfields;
 
         tmp = s[sidx];
-        if (!*tmp) {
-            if (!success)
-                config_error_add("Missing condition(s)");
-            return success;
-        }
-
         Strcpy(buf, tmp);
         conditions_bitmask = str2conditionbitmask(buf);
 
@@ -2875,8 +2875,10 @@ parse_condition(char (*s)[QBUFSZ], int sidx)
             } else {
                 int k = match_str2clr(subfields[i]);
 
-                if (k >= CLR_MAX)
+                if (k >= CLR_MAX) {
+                    config_error_add("bad color %d", k);
                     return FALSE;
+                }
                 coloridx = k;
             }
         }
@@ -2884,10 +2886,10 @@ parse_condition(char (*s)[QBUFSZ], int sidx)
            condition array according to color chosen as index */
 
         g.cond_hilites[coloridx] |= conditions_bitmask;
-        success = TRUE;
+        result = TRUE;
         sidx++;
     }
-    return TRUE;
+    return result;
 }
 
 void