Skip to content

Commit

Permalink
Fix incomplete duplication of REPT nodes
Browse files Browse the repository at this point in the history
"Initialization, sizeof, and the assignment operator ignore the flexible array member."
Oops!
  • Loading branch information
ISSOtm committed Oct 4, 2020
1 parent 423a7c4 commit c246942
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/asm/fstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ bool yywrap(void)

/* 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;

Expand Down

0 comments on commit c246942

Please sign in to comment.