Avoid using EXPAND_AND_STR with external defines

There is no guarantee that they are purely numeric, use the values instead
This commit is contained in:
ISSOtm
2021-01-22 08:37:40 +01:00
parent 09f16bda4a
commit 993c034039
2 changed files with 4 additions and 5 deletions

View File

@@ -36,7 +36,7 @@ static uint32_t maxUniqueID = 0;
* guarantees the size of the buffer will be correct. I was unable to find a * guarantees the size of the buffer will be correct. I was unable to find a
* better solution, but if you have one, please feel free! * better solution, but if you have one, please feel free!
*/ */
static char uniqueIDBuf[] = "_" EXPAND_AND_STR(UINT32_MAX); static char uniqueIDBuf[] = "_u4294967295"; // UINT32_MAX
static char *uniqueIDPtr = NULL; static char *uniqueIDPtr = NULL;
struct MacroArgs *macro_GetCurrentArgs(void) struct MacroArgs *macro_GetCurrentArgs(void)
@@ -61,13 +61,12 @@ void macro_AppendArg(struct MacroArgs **argPtr, char *s)
{ {
#define macArgs (*argPtr) #define macArgs (*argPtr)
if (macArgs->nbArgs == MAXMACROARGS) if (macArgs->nbArgs == MAXMACROARGS)
error("A maximum of " EXPAND_AND_STR(MAXMACROARGS) error("A maximum of " EXPAND_AND_STR(MAXMACROARGS) " arguments is allowed\n");
" arguments is allowed\n");
if (macArgs->nbArgs >= macArgs->capacity) { if (macArgs->nbArgs >= macArgs->capacity) {
macArgs->capacity *= 2; macArgs->capacity *= 2;
/* Check that overflow didn't roll us back */ /* Check that overflow didn't roll us back */
if (macArgs->capacity <= macArgs->nbArgs) if (macArgs->capacity <= macArgs->nbArgs)
fatalerror("Failed to add new macro argument: possible capacity overflow\n"); fatalerror("Failed to add new macro argument: capacity overflow\n");
macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity)); macArgs = realloc(macArgs, SIZEOF_ARGS(macArgs->capacity));
if (!macArgs) if (!macArgs)
fatalerror("Error adding new macro argument: %s\n", strerror(errno)); fatalerror("Error adding new macro argument: %s\n", strerror(errno));

View File

@@ -435,7 +435,7 @@ static void readAssertion(FILE *file, struct Assertion *assert,
char const *fileName, uint32_t i, char const *fileName, uint32_t i,
struct Section *fileSections[], struct FileStackNode fileNodes[]) struct Section *fileSections[], struct FileStackNode fileNodes[])
{ {
char assertName[sizeof("Assertion #" EXPAND_AND_STR(UINT32_MAX))]; char assertName[sizeof("Assertion #4294967295")]; // UINT32_MAX
snprintf(assertName, sizeof(assertName), "Assertion #%" PRIu32, i); snprintf(assertName, sizeof(assertName), "Assertion #%" PRIu32, i);