From 7728e093378d1ef0e7fb0e633ed26c036f896766 Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Thu, 30 May 2024 12:27:35 -0400 Subject: [PATCH] Don't allow duplicate arg names in function definitions. --- src/err.h | 4 +++- src/userfns.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/err.h b/src/err.h index a0388bc6..f957d2ee 100644 --- a/src/err.h +++ b/src/err.h @@ -122,6 +122,7 @@ #define E_TIME_TWICE 102 #define E_DURATION_NO_AT 103 #define E_EXPECTING_WEEKDAY 104 +#define E_REPEATED_ARG 105 #ifdef MK_GLOBALS #undef EXTERN @@ -244,7 +245,8 @@ EXTERN char *ErrMsg[] "String too long", "Time specified twice", "Cannot specify DURATION without specifying AT", - "Expecting weekday name" + "Expecting weekday name", + "Duplicate argument name" } #endif /* MK_GLOBALS */ ; diff --git a/src/userfns.c b/src/userfns.c index a8a27788..a267ebea 100644 --- a/src/userfns.c +++ b/src/userfns.c @@ -100,6 +100,7 @@ int DoFset(ParsePtr p) int c; UserFunc *func; Var *v; + Var *local; int orig_namelen; DynamicBuffer buf; @@ -168,6 +169,16 @@ int DoFset(ParsePtr p) DestroyUserFunc(func); return E_BAD_ID; } + /* If we've already seen this local variable, error */ + local = func->locals; + while(local) { + if (!StrinCmp(DBufValue(&buf), local->name, VAR_NAME_LEN)) { + DBufFree(&buf); + DestroyUserFunc(func); + return E_REPEATED_ARG; + } + local = local->next; + } v = NEW(Var); if (!v) { DBufFree(&buf);