diff mbox

[v4,23/25] return an error if too few args

Message ID 20170331014459.9351-24-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Luc Van Oostenryck March 31, 2017, 1:44 a.m. UTC
In evaluate_call(), argumenst are evaluated an a diagnostic
is emitted if the number of args is not what is expected.

Good.
However, the processing continues nevertheless.
If too much args were given, this doesn't matter much
but if too few are given we need to check a bit everywhere
for possible NULL args.

Avoid this by returning early an error if there was too few
arguments.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 evaluate.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/evaluate.c b/evaluate.c
index 46ea10ed8..0cec215ba 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -3019,10 +3019,12 @@  static struct symbol *evaluate_call(struct expression *expr)
 			return NULL;
 		args = expression_list_size(expr->args);
 		fnargs = symbol_list_size(ctype->arguments);
-		if (args < fnargs)
+		if (args < fnargs) {
 			expression_error(expr,
 				     "not enough arguments for function %s",
 				     show_ident(sym->ident));
+			return NULL;
+		}
 		if (args > fnargs && !ctype->variadic)
 			expression_error(expr,
 				     "too many arguments for function %s",