A 30 year old bug fixed

17 views
Skip to first unread message

The Beez

unread,
Jan 14, 2024, 8:38:40 AMJan 14
to 4tH-compiler
Hi 4tH-ers!

If you follow the code updates closely, you'll find two lines are added to exec_4th.c - one for the changelog and one single line of code.

So why is that? Now you gotta know that before I go to sleep I always take a look at code. It might be some new code I added, it might be some old code. A few nights ago I looked at the exec_4th.c code and found something missing.

The initialization of the VM has two branches - one for newly started bytecode programs and one for paused bytecode. Now, one may expect that paused bytecode programs are fully initialized. It's just the frame that has to restated. But it is different for new bytecode programs.

And every single variable was initialized, except for the hidden HLD. That means that the pointer to that one was pointing to a random place in memory. That's not too bad, because <# initializes it. But what if we tried # without calling #> first?

I tried. Apart from an error message nothing disastrous happened. But that was just GCC. What about other environments or compilers? Even some compilers I was not aware of (after all, 4tH was written with porting in mind).

So I decided to do the smart thing, that was to fix it. Now an uninitialized # is accepted without error. You might not like that, but IMHO it is better than a possible crash.

A 30 year old (potential) bug. Who would have thought after the amount of code that went through in those 30 years.

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages