Browse Source

cpitf.c, cp_istrue(), avoid surplus Warning Message when an `if' condition expands to nothing

When in expression
  if $var ...
the variable `var' was undefined, then
ngspice printed a surplus warning message
>  Warning: NULL arithmetic expression
in addition to the error message
>  Error: var: no such variable.

ngspice continues to process the conditional construct
  and evaluates the condition as "FALSE"
pre-master-46
h_vogt 10 years ago
committed by rlar
parent
commit
8b709a394f
  1. 1
      examples/control_structs/if-test-1.cir
  2. 3
      src/frontend/cpitf.c

1
examples/control_structs/if-test-1.cir

@ -36,7 +36,6 @@ end
echo echo
echo "expect Error: testvar_d: no such variable." echo "expect Error: testvar_d: no such variable."
echo "expect Warning: NULL arithmetic expression"
* in cp_istrue(): wl!=NULL then wl==NULL names==NULL v==NULL * in cp_istrue(): wl!=NULL then wl==NULL names==NULL v==NULL
if $testvar_d if $testvar_d
echo "FAIL: you should not see this" echo "FAIL: you should not see this"

3
src/frontend/cpitf.c

@ -306,6 +306,9 @@ cp_istrue(wordlist *wl)
/* First do all the csh-type stuff here... */ /* First do all the csh-type stuff here... */
wl = wl_copy(wl); wl = wl_copy(wl);
wl = cp_variablesubst(wl); wl = cp_variablesubst(wl);
/* return FALSE if this did not expand to anything */
if (!wl)
return FALSE;
wl = cp_bquote(wl); wl = cp_bquote(wl);
cp_striplist(wl); cp_striplist(wl);

Loading…
Cancel
Save