shithub: rgbds

Download patch

ref: 80218fa109e5f1726737a603eecfd1cb7f233b8b
parent: fee8a58b77eeb6002b0cf57d433e89b68cfc870a
author: ISSOtm <eldredhabert0@gmail.com>
date: Tue May 12 12:43:59 EDT 2020

Fix array overflow on invalid macro arg evaluation

`macro_GetArg` had not been changed after the previous commit; however,
the old code relied on the `macroArgs->args` array being at least
`MAXMACROARGS` entries large (which was the case until the last commit).
The boundary against which it checked would have better been written as
`sizeof(macroArgs->args)/sizeof(macroArgs->args[0])`, I guess, but what's
done is done.

--- a/src/asm/macro.c
+++ b/src/asm/macro.c
@@ -64,7 +64,8 @@
 {
 	uint32_t realIndex = i + macroArgs->shift - 1;
 
-	return realIndex >= MAXMACROARGS ? NULL : macroArgs->args[realIndex];
+	return realIndex >= macroArgs->nbArgs ? NULL
+					      : macroArgs->args[realIndex];
 }
 
 uint32_t macro_GetUniqueID(void)