ref: 596e17ee61ea020a218d2885d86af195f088d8c6
parent: 363b3d01341f3511b9316a78c7686e15901e5d66
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Wed Mar 31 10:41:38 EDT 2021
Factor out a common `strlen` into `beginExpansion` This avoids the possibility of `size` not matching `str`
--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -747,10 +747,11 @@
return expansion;
}
-static void beginExpansion(size_t distance, uint8_t skip,
- char const *str, size_t size, bool owned,
+static void beginExpansion(size_t distance, uint8_t skip, char const *str, bool owned,
char const *name)
{
+ size_t size = strlen(str);
+
/* Do not expand empty strings */
if (!size)
return;
@@ -929,7 +930,7 @@
goto restart;
}
- beginExpansion(distance, 2, str, strlen(str), c == '#', NULL);
+ beginExpansion(distance, 2, str, c == '#', NULL);
/*
* Assuming macro args can't be recursive (I'll be damned if a way
@@ -949,7 +950,7 @@
char const *ptr = readInterpolation();
if (ptr) {
- beginExpansion(distance, 0, ptr, strlen(ptr), false, ptr);
+ beginExpansion(distance, 0, ptr, false, ptr);
goto restart;
}
}
@@ -1418,7 +1419,7 @@
char const *ptr = readInterpolation();
if (ptr) {
- beginExpansion(0, 0, ptr, strlen(ptr), false, ptr);
+ beginExpansion(0, 0, ptr, false, ptr);
continue; /* Restart, reading from the new buffer */
}
} else if (c == EOF || c == '\r' || c == '\n' || c == '"') {
@@ -2100,8 +2101,7 @@
if (sym && sym->type == SYM_EQUS) {
char const *s = sym_GetStringValue(sym);
- beginExpansion(0, 0, s, strlen(s), false,
- sym->name);
+ beginExpansion(0, 0, s, false, sym->name);
continue; /* Restart, reading from the new buffer */
}
}