shithub: rgbds

Download patch

ref: 021990b8e0c3c05684b3b46595741a146367c0a4
parent: 540564694c0189c6b26a033c16f1393cb0184f9a
author: dbrotz <43593771+dbrotz@users.noreply.github.com>
date: Sun May 5 16:21:55 EDT 2019

Properly check if a symbol's full name is too long

--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -154,12 +154,14 @@
  * Creates the full name of a local symbol in a given scope, by prepending
  * the name with the parent symbol's name.
  */
-static size_t fullSymbolName(char *output, size_t outputSize, char *localName,
-			     const struct sSymbol *scope)
+static void fullSymbolName(char *output, size_t outputSize, char *localName,
+			   const struct sSymbol *scope)
 {
 	const struct sSymbol *parent = scope->pScope ? scope->pScope : scope;
+	int n = snprintf(output, outputSize, "%s%s", parent->tzName, localName);
 
-	return snprintf(output, outputSize, "%s%s", parent->tzName, localName);
+	if (n >= (int)outputSize)
+		fatalerror("Symbol too long");
 }
 
 /*
@@ -561,9 +563,6 @@
 void sym_AddLocalReloc(char *tzSym)
 {
 	if (pScope) {
-		if (strlen(tzSym) + strlen(pScope->tzName) > MAXSYMLEN)
-			fatalerror("Symbol too long");
-
 		char fullname[MAXSYMLEN + 1];
 
 		fullSymbolName(fullname, sizeof(fullname), tzSym, pScope);