shithub: rgbds

Download patch

ref: c24694233f5f1103a33d3476f44cf47099936a84
parent: 423a7c48994fc9430960f83955d6697d484e342a
author: ISSOtm <[email protected]>
date: Wed Sep 30 09:16:23 EDT 2020

Fix incomplete duplication of REPT nodes

"Initialization, sizeof, and the assignment operator ignore the flexible array member."
Oops!

--- a/src/asm/fstack.c
+++ b/src/asm/fstack.c
@@ -202,12 +202,13 @@
 
 		/* If the node is referenced, we can't edit it; duplicate it */
 		if (contextStack->fileInfo->referenced) {
-			struct FileStackReptNode *copy = malloc(sizeof(*copy) + sizeof(copy->iters[0]) * fileInfo->reptDepth);
+			size_t size = sizeof(*fileInfo) + sizeof(fileInfo->iters[0]) * fileInfo->reptDepth;
+			struct FileStackReptNode *copy = malloc(size);
 
 			if (!copy)
 				fatalerror("Failed to duplicate REPT file node: %s\n", strerror(errno));
 			/* Copy all info but the referencing */
-			*copy = *fileInfo;
+			memcpy(copy, fileInfo, size);
 			copy->node.next = NULL;
 			copy->node.referenced = false;