shithub: rgbds

Download patch

ref: 8a59994c0dd9e15fd50462d1242377fedcdcdad4
parent: f2e1b7d8683b46f9631b5f550605f396fcf21f65
author: ISSOtm <[email protected]>
date: Thu Oct 10 21:00:13 EDT 2019

Fix false positives in `readstr`
Reading the byte `EOF & 0xFF` would cause an incorrect termination

--- a/src/link/object.c
+++ b/src/link/object.c
@@ -117,6 +117,7 @@
 	do {
 		/* Prepare going to next char */
 		index++;
+
 		/* If the buffer isn't suitable to write the next char... */
 		if (index >= capacity || !str) {
 			capacity *= 2;
@@ -125,10 +126,13 @@
 			if (!str)
 				return NULL;
 		}
+
 		/* Read char */
-		str[index] = getc(file);
-		if (str[index] == EOF)
+		int byte = getc(file);
+
+		if (byte == EOF)
 			return NULL;
+		str[index] = byte;
 	} while (str[index]);
 	return str;
 }