Uninitialized vars in loop carried over to next iteration.

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!

Uninitialized vars in loop carried over to next iteration.

Postby Accensus » Fri Jun 11, 2021 6:18 am

Title sucks. Ran out of characters. Here's the situation:
Run the attached file and summon VarTest. The print result will be 0, 0, 1 for both the static and non-static calls. Array size will be 2. The correct and expected result is "0, 0, 0" with array size of 3.

Here are the two ways to "fix" this:
1. Uncomment the "Console.Printf(am.GetClassName());" lines. If something is referenced above the didInsert definition, the variable will be correctly initialized.
2. Explicitly initialize didInsert by setting it to false.

tl;dr something about the vars not being implicitly initialized.
You do not have the required permissions to view the files attached to this post.
User avatar
Does not use federally approved humor.
Joined: 11 Feb 2016
Location: Somalia
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Uninitialized vars in loop carried over to next iteratio

Postby phantombeta » Fri Jun 11, 2021 6:27 am

This is caused by registers not being marked as dirty, so the local var init code thinks they're still clean and don't need to be implicitly initialized.
This is most likely going to be a pain in the ass to find every missing case of a missing dirty flag, so I'm personally not even touching this. If it just implicitly initialized anything without an initializer this wouldn't have ever happened, but y'know, possible microscopic performance losses were a bigger concern than ensuring safety here.
Oh, and by the way, this obviously means the uninitialized var reinterpret cast bug is still around, just harder to trigger.
User avatar
Tired of being treated like trash by control freaks
Joined: 02 May 2013

Re: Uninitialized vars in loop carried over to next iteratio

Postby Graf Zahl » Fri Jun 11, 2021 6:43 am

Obviously this is just a bad coding example. Regardless of what a language does, you should never *ever* operate on uninitialized variables.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Joined: 19 Jul 2003
Location: Germany

Return to Bugs

Who is online

Users browsing this forum: No registered users and 1 guest