Allow empty macro arguments, with a warning

Fixes #739
This commit is contained in:
Rangi
2021-02-17 18:54:02 -05:00
committed by Rangi
parent 63d15ac8c9
commit 1dafc1c762
11 changed files with 106 additions and 23 deletions

View File

@@ -2,6 +2,7 @@
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -58,9 +59,15 @@ struct MacroArgs *macro_NewArgs(void)
return args;
}
void macro_AppendArg(struct MacroArgs **argPtr, char *s)
void macro_AppendArg(struct MacroArgs **argPtr, char *s, bool isLastArg)
{
#define macArgs (*argPtr)
if (s[0] == '\0') {
/* Zero arguments are parsed as a spurious empty argument; do not append it */
if (isLastArg && !macArgs->nbArgs)
return;
warning(WARNING_EMPTY_MACRO_ARG, "Empty macro argument\n");
}
if (macArgs->nbArgs == MAXMACROARGS)
error("A maximum of " EXPAND_AND_STR(MAXMACROARGS) " arguments is allowed\n");
if (macArgs->nbArgs >= macArgs->capacity) {