mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix incomplete duplication of REPT nodes
"Initialization, sizeof, and the assignment operator ignore the flexible array member." Oops!
This commit is contained in:
@@ -202,12 +202,13 @@ bool yywrap(void)
|
|||||||
|
|
||||||
/* If the node is referenced, we can't edit it; duplicate it */
|
/* If the node is referenced, we can't edit it; duplicate it */
|
||||||
if (contextStack->fileInfo->referenced) {
|
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)
|
if (!copy)
|
||||||
fatalerror("Failed to duplicate REPT file node: %s\n", strerror(errno));
|
fatalerror("Failed to duplicate REPT file node: %s\n", strerror(errno));
|
||||||
/* Copy all info but the referencing */
|
/* Copy all info but the referencing */
|
||||||
*copy = *fileInfo;
|
memcpy(copy, fileInfo, size);
|
||||||
copy->node.next = NULL;
|
copy->node.next = NULL;
|
||||||
copy->node.referenced = false;
|
copy->node.referenced = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user