Reproduction script:
struct IntList
{
int count;
int items[1000];
};
local IntList gMyList;
void List_Add(IntList& this_, int value)
{
this_.items[this_.count++] = value;
}
List_Add(gMyList, 5);
Printf("Count = %d, item 0 = %d\n", gMyList.count, gMyList.items[0]);
The expected message is of course “Count = 1, item 0 = 5”. However, in 010 Editor 16.0.2 we instead see “Count = 2, item 0 = 0”. The count++ was executed an additional time, and the value was written to index 1.
The bug can be avoided by running the increment as a separate statement:
this_.items[this_.count] = value;
this_.count++;