build and bug fixes for USE_OLDARGS
New: call to panic() in impossible() used arbitrary string as a
format so was vulnerable to percent signs in that string. (This
potentially serious problem is not limited to USE_OLDARGS.)
Old: revised message string for impossible ("save/restore might fix
this" instead of "perhaps you'd better quit") passed wrong number of
arguments to pline() when using the clumsy VA_PASSx() mechanism (was
missing arg 0 for the fixed-arg format argument).
Old: varargs config_error_add() in files.c wouldn't compile for
USE_OLDARGS. Evidently no one has been impacted by that but this
fixes it anyway. (Two problems: prototype used FDECL() when it
should have been using VDECL(), and calls to config_error_add() in
the same file would need the VA_PASSx() stuff to force presence of
all optional args. I moved it instead of adding the latter.)
This commit is contained in:
60
src/files.c
60
src/files.c
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 files.c $NHDT-Date: 1526382938 2018/05/15 11:15:38 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.240 $ */
|
||||
/* NetHack 3.6 files.c $NHDT-Date: 1541719971 2018/11/08 23:32:51 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.242 $ */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/*-Copyright (c) Derek S. Ray, 2015. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
@@ -2494,7 +2494,7 @@ char *origbuf;
|
||||
n = atoi(bufp);
|
||||
if (n < 1) {
|
||||
config_error_add(
|
||||
"Illegal value in MAX_STATUENAME_RANK (minimum is 1).");
|
||||
"Illegal value in MAX_STATUENAME_RANK (minimum is 1).");
|
||||
return FALSE;
|
||||
}
|
||||
sysopt.tt_oname_maxrank = n;
|
||||
@@ -2736,7 +2736,7 @@ struct _config_error_frame {
|
||||
struct _config_error_frame *next;
|
||||
};
|
||||
|
||||
struct _config_error_frame *config_error_data = (struct _config_error_frame *)0;
|
||||
static struct _config_error_frame *config_error_data = 0;
|
||||
|
||||
void
|
||||
config_error_init(from_file, sourcename, secure)
|
||||
@@ -2745,7 +2745,7 @@ const char *sourcename;
|
||||
boolean secure;
|
||||
{
|
||||
struct _config_error_frame *tmp = (struct _config_error_frame *)
|
||||
alloc(sizeof(struct _config_error_frame));
|
||||
alloc(sizeof (struct _config_error_frame));
|
||||
|
||||
tmp->line_num = 0;
|
||||
tmp->num_errors = 0;
|
||||
@@ -2754,8 +2754,8 @@ boolean secure;
|
||||
tmp->secure = secure;
|
||||
tmp->origline[0] = '\0';
|
||||
if (sourcename && sourcename[0]) {
|
||||
(void) strncpy(tmp->source, sourcename, sizeof(tmp->source)-1);
|
||||
tmp->source[sizeof(tmp->source)-1] = '\0';
|
||||
(void) strncpy(tmp->source, sourcename, sizeof (tmp->source) - 1);
|
||||
tmp->source[sizeof (tmp->source) - 1] = '\0';
|
||||
} else
|
||||
tmp->source[0] = '\0';
|
||||
|
||||
@@ -2778,49 +2778,43 @@ const char *line;
|
||||
ced->line_num++;
|
||||
ced->origline_shown = FALSE;
|
||||
if (line && line[0]) {
|
||||
(void) strncpy(ced->origline, line, sizeof(ced->origline)-1);
|
||||
ced->origline[sizeof(ced->origline)-1] = '\0';
|
||||
(void) strncpy(ced->origline, line, sizeof (ced->origline) - 1);
|
||||
ced->origline[sizeof (ced->origline) - 1] = '\0';
|
||||
} else
|
||||
ced->origline[0] = '\0';
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*VARARGS1*/
|
||||
void config_error_add
|
||||
VA_DECL(const char *, str)
|
||||
/* varargs 'config_error_add()' moved to pline.c */
|
||||
void
|
||||
config_erradd(buf)
|
||||
const char *buf;
|
||||
{
|
||||
char buf[BUFSZ];
|
||||
char lineno[QBUFSZ];
|
||||
|
||||
VA_START(str);
|
||||
VA_INIT(str, char *);
|
||||
|
||||
Vsprintf(buf, str, VA_ARGS);
|
||||
if (!buf || !*buf)
|
||||
buf = "Unknown error";
|
||||
|
||||
if (!config_error_data) {
|
||||
pline("%s.", *buf ? buf : "Unknown error");
|
||||
/* assumes pline() is using raw_printf() as this stage */
|
||||
pline("config_error_add: %s.", buf);
|
||||
wait_synch();
|
||||
return;
|
||||
}
|
||||
|
||||
config_error_data->num_errors++;
|
||||
if (!config_error_data->origline_shown
|
||||
&& !config_error_data->secure) {
|
||||
if (!config_error_data->origline_shown && !config_error_data->secure) {
|
||||
pline("\n%s", config_error_data->origline);
|
||||
config_error_data->origline_shown = TRUE;
|
||||
}
|
||||
if (config_error_data->line_num > 0
|
||||
&& !config_error_data->secure) {
|
||||
Sprintf(lineno, "Line %i: ", config_error_data->line_num);
|
||||
if (config_error_data->line_num > 0 && !config_error_data->secure) {
|
||||
Sprintf(lineno, "Line %d: ", config_error_data->line_num);
|
||||
} else
|
||||
lineno[0] = '\0';
|
||||
pline("%s %s%s.",
|
||||
config_error_data->secure ? "Error:" : " *",
|
||||
lineno,
|
||||
*buf ? buf : "Unknown error");
|
||||
|
||||
VA_END();
|
||||
pline("%s %s%s.", config_error_data->secure ? "Error:" : " *",
|
||||
lineno, buf);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -2833,17 +2827,14 @@ config_error_done()
|
||||
return 0;
|
||||
n = config_error_data->num_errors;
|
||||
if (n) {
|
||||
pline("\n%i error%s in %s.\n", n,
|
||||
pline("\n%d error%s in %s.\n", n,
|
||||
(n > 1) ? "s" : "",
|
||||
*config_error_data->source
|
||||
? config_error_data->source : configfile);
|
||||
wait_synch();
|
||||
}
|
||||
|
||||
config_error_data = tmp->next;
|
||||
|
||||
free(tmp);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -3108,7 +3099,8 @@ boolean FDECL((*proc), (char *));
|
||||
char *section;
|
||||
char *bufp = find_optparam(buf);
|
||||
if (!bufp) {
|
||||
config_error_add("Format is CHOOSE=section1,section2,...");
|
||||
config_error_add(
|
||||
"Format is CHOOSE=section1,section2,...");
|
||||
rv = FALSE;
|
||||
free(buf);
|
||||
buf = (char *) 0;
|
||||
@@ -3199,8 +3191,8 @@ int which_set;
|
||||
}
|
||||
if (!chosen_symset_end)
|
||||
config_error_add("Missing finish for symset \"%s\"",
|
||||
symset[which_set].name ? symset[which_set].name
|
||||
: "unknown");
|
||||
symset[which_set].name ? symset[which_set].name
|
||||
: "unknown");
|
||||
|
||||
config_error_done();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user