From bfab06e04be77b33db6a9411719e48589ffc29be Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Wed, 31 Aug 2022 15:42:30 +0200 Subject: [PATCH] Improved error message: more info on the bad set form --- src/frontend/variable.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/frontend/variable.c b/src/frontend/variable.c index 4b29b0dd3..9410d4db2 100644 --- a/src/frontend/variable.c +++ b/src/frontend/variable.c @@ -390,10 +390,13 @@ static void update_option_variables(const char *sz_var_name, Without quotes tokens like 2N5401_C will be evaluated as real number 2n, i.e. 2e-9 */ struct variable *cp_setparse(wordlist *wl) { - char *name = NULL, *val, *copyval, *s, *ss; + char *name = NULL, *val, *copyval, *s, *ss, *printout = NULL; struct variable *listv = NULL, *vv, *lv = NULL; struct variable *vars = NULL; + if (wl) + printout = wl_flatten(wl); + /* Step through the list of words. Words may be various combinations of * the information needed to set a variable. For example, to set x to * the value 3, the data could be supplied as one word x=3, two words @@ -417,8 +420,9 @@ struct variable *cp_setparse(wordlist *wl) if (wl && eq(wl->wl_word, "=")) { /* name= */ wl = wl->wl_next; if (wl == NULL) { - fprintf(cp_err, "Error: bad set form.\n"); - tfree(name); /*DG: cp_unquote Memory leak*/ + fprintf(cp_err, "Error: bad set form in line\n %s", printout); + tfree(name); + tfree(printout); if (ft_stricterror) controlled_exit(EXIT_BAD); return NULL; @@ -446,8 +450,9 @@ struct variable *cp_setparse(wordlist *wl) } } else { - fprintf(cp_err, "Error: bad set form.\n"); - tfree(name); /*DG: cp_unquote Memory leak: free name befor exiting */ + fprintf(cp_err, "Error: bad set form in line\n %s", printout); + tfree(name); + tfree(printout); if (ft_stricterror) controlled_exit(EXIT_BAD); return NULL; @@ -505,8 +510,9 @@ struct variable *cp_setparse(wordlist *wl) wl = wl->wl_next; } if (balance && !wl) { - fprintf(cp_err, "Error: bad set form.\n"); - tfree(name); /* va: cp_unquote memory leak: free name before exiting */ + fprintf(cp_err, "Error: bad set form in line\n %s", printout); + tfree(name); + tfree(printout); if (ft_stricterror) controlled_exit(EXIT_BAD); return NULL; @@ -546,6 +552,9 @@ struct variable *cp_setparse(wordlist *wl) if (name) { tfree(name); } + if (printout) { + tfree(printout); + } return vars; } /* end of function cp_setparse */