]> granicus.if.org Git - nethack/commitdiff
config error reporting
authorPatR <rankin@nethack.org>
Fri, 21 May 2021 15:52:18 +0000 (08:52 -0700)
committerPatR <rankin@nethack.org>
Fri, 21 May 2021 15:52:18 +0000 (08:52 -0700)
Try to handle the convoluted error handling better.  Not very
thoroughly tested...

doc/fixes37.0
src/files.c

index b2420cd14077bfd7cad3d8fd2cfbbf2a583163af..01531c166182f4a60a3a40922ec64580c093b33c 100644 (file)
@@ -690,7 +690,7 @@ fix globby_bill_fixup to use shopkeeper instead of Null for glob pricing
 applying a book to check readability treated novels as if they were spellbooks
 #version was leaving the 'in_lua' flag set and if subsequent 'O' issued an
        error (example was an attempt to interactively set bouldersym to an
-       invalid value), the error routine reporting crashed via segfault
+       invalid value), the error reporting routine crashed via segfault
 
 curses: 'msg_window' option wasn't functional for curses unless the binary
        also included tty support
index 66f50963305492946d7843870a4888fc19c7950a..eff4e04fd2a6006a1218610f22059730d40c5847 100644 (file)
@@ -2837,7 +2837,7 @@ void
 config_error_init(boolean from_file, const char *sourcename, boolean secure)
 {
     struct _config_error_frame *tmp = (struct _config_error_frame *)
-        alloc(sizeof (struct _config_error_frame));
+                                                           alloc(sizeof *tmp);
 
     tmp->line_num = 0;
     tmp->num_errors = 0;
@@ -2913,6 +2913,14 @@ config_erradd(const char *buf)
     if (!buf || !*buf)
         buf = "Unknown error";
 
+    if (!g.program_state.config_error_ready) {
+        /* either very early, where pline() will use raw_print(), or
+           player gave bad value when prompted by interactive 'O' command */
+        pline("%s%s.", !iflags.window_inited ? "config_error_add: " : "", buf);
+        wait_synch();
+        return;
+    }
+
     if (iflags.in_lua) {
         struct _config_error_errmsg *dat
                          = (struct _config_error_errmsg *) alloc(sizeof *dat);
@@ -2924,14 +2932,6 @@ config_erradd(const char *buf)
         return;
     }
 
-    if (!config_error_data) {
-        /* either very early, where pline() will use raw_print(), or
-           player gave bad value when prompted by interactive 'O' command */
-        pline("%s%s.", !iflags.window_inited ? "config_error_add: " : "", buf);
-        wait_synch();
-        return;
-    }
-
     config_error_data->num_errors++;
     if (!config_error_data->origline_shown && !config_error_data->secure) {
         pline("\n%s", config_error_data->origline);
@@ -2956,15 +2956,14 @@ config_error_done(void)
         return 0;
     n = config_error_data->num_errors;
     if (n) {
-        pline("\n%d error%s in %s.\n", n,
-                   (n > 1) ? "s" : "",
-                   *config_error_data->source
-              ? config_error_data->source : configfile);
+        pline("\n%d error%s in %s.\n", n, plur(n),
+              *config_error_data->source ? config_error_data->source
+                                         : configfile);
         wait_synch();
     }
     config_error_data = tmp->next;
     free(tmp);
-    g.program_state.config_error_ready = FALSE;
+    g.program_state.config_error_ready = (config_error_data != 0);
     return n;
 }