nsc: Rename nstr_exec_val() to nstr_eval() and tighten contract

nstr_exec_val() can produce three different error values: NSC_NOTYPE
on invalid category, invalid type with zero val_as.lng on invalid type
(this is a bug), and the wanted type with zero val_s when it can't
coerce.  None of these should ever happen.

Fix it to always produce an NSC_NOTYPE error value.  Fix up callers to
check for it.

Specify the result's type is promoted on success.  Ensure it is even
when the argument is NSC_VAL with an unpromoted type, which is
invalid.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2014-02-02 09:39:35 +01:00
parent 5a1544f925
commit 143a4e4e6f
6 changed files with 29 additions and 20 deletions

View file

@ -28,6 +28,7 @@
*
* Known contributors to this file:
* Dave Pare, 1986
* Markus Armbruster, 2004-2014
*/
#include <config.h>
@ -135,7 +136,9 @@ code_char(struct valstr val, struct sctstr *sp)
int n;
int large = val.val_type != NSC_CHAR && val.val_type != NSC_UCHAR;
nstr_exec_val(&val, player->cnum, sp, NSC_LONG);
nstr_eval(&val, player->cnum, sp, NSC_LONG);
if (CANT_HAPPEN(val.val_type != NSC_LONG))
return ' ';
amt = val.val_as.lng;
if (amt <= 0)
return ' ';