diff options
author | Steve Bennett <steveb@workware.net.au> | 2017-08-05 12:33:13 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-08-07 20:36:27 +1000 |
commit | 028dd5dd2f58456e27cd6c54b1539fc16406bc9a (patch) | |
tree | f57eed4b5be14a97e38031154468bdeca3e07414 | |
parent | 59f01cb74b4b6f8c32cc4083735050b233ad4380 (diff) | |
download | jimtcl-028dd5dd2f58456e27cd6c54b1539fc16406bc9a.zip jimtcl-028dd5dd2f58456e27cd6c54b1539fc16406bc9a.tar.gz jimtcl-028dd5dd2f58456e27cd6c54b1539fc16406bc9a.tar.bz2 |
expr: Check for missing operand to operator
Reported-by: Ryan Whitworth <me@ryanwhitworth.com>
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 14 | ||||
-rw-r--r-- | regtest.tcl | 5 |
2 files changed, 19 insertions, 0 deletions
@@ -8899,12 +8899,26 @@ noargs: if (op->arity >= 3) { node->ternary = Jim_StackPop(&builder->stack); + if (node->ternary == NULL) { + goto missingoperand; + } } if (op->arity >= 2) { node->right = Jim_StackPop(&builder->stack); + if (node->right == NULL) { + printf("missing right term to operator %s\n", op->name); + goto missingoperand; + } } if (op->arity >= 1) { node->left = Jim_StackPop(&builder->stack); + if (node->left == NULL) { +missingoperand: + Jim_SetResultFormatted(interp, "missing operand to %s in expression: \"%#s\"", op->name, builder->exprObjPtr); + builder->next--; + return JIM_ERR; + + } } /* Now push the node */ diff --git a/regtest.tcl b/regtest.tcl index aae22d5..0833b39 100644 --- a/regtest.tcl +++ b/regtest.tcl @@ -340,6 +340,11 @@ puts "TEST 48 PASSED" catch {format %1.9999999999f 1.0} puts "TEST 49 PASSED" +# REGTEST 50 +# expr missing operand +catch {expr {>>-$x}} +puts "TEST 50 PASSED" + # TAKE THE FOLLOWING puts AS LAST LINE puts "--- ALL TESTS PASSED ---" |