From c5debe2304230d7b2d054634243c386f87465dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Mon, 22 Oct 2012 16:22:15 +0000 Subject: [PATCH] [INTERPRETER] * BUG: The event handler check routine should not crash anymore. git-svn-id: svn://localhost/gambas/trunk@5249 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_event.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/main/gbx/gbx_event.c b/main/gbx/gbx_event.c index f0a1d7559..b3f22db0b 100644 --- a/main/gbx/gbx_event.c +++ b/main/gbx/gbx_event.c @@ -42,16 +42,23 @@ static EVENT_POST *_post_list = NULL; static void check_event_method(CLASS *class, const char *name, CLASS_DESC_METHOD *desc, CLASS_EVENT *event) { - if (event->n_param < desc->npmin) + int n = event->n_param; + + if (n < desc->npmin) { /*printf("event->n_param = %d desc->npmin = %d desc->npmax = %d\n", event->n_param, desc->npmin, desc->npmax);*/ THROW(E_EVENT, CLASS_get_name(class), name, "Too many arguments"); } - if (event->n_param > desc->npmax && !desc->npvar) - THROW(E_EVENT, CLASS_get_name(class), name, "Not enough arguments"); + if (n > desc->npmax) + { + if (!desc->npvar) + THROW(E_EVENT, CLASS_get_name(class), name, "Not enough arguments"); + + n = desc->npmax; + } - if (TYPE_compare_signature(desc->signature, desc->npmax, (TYPE *)event->param, desc->npmax)) + if (TYPE_compare_signature(desc->signature, n, (TYPE *)event->param, n)) THROW(E_EVENT, CLASS_get_name(class), name, "Type mismatch"); if (desc->type != T_VOID)