'out' can be ommited in overrides, causing silent bugs.

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!

'out' can be ommited in overrides, causing silent bugs.

Postby Accensus » Sat Nov 20, 2021 4:38 am

Take this code for example:

Code: Select allExpand view
class BaseClass abstract
{
   abstract void F1(out int ticker);
   abstract void F2(out int ticker);
}

class DerivedClass : BaseClass
{
   override void F1(out int ticker)
   {
      Console.Printf("F1: %i", ticker);
   }
   override void F2(int ticker)
   {
      Console.Printf("F2: %i", ticker);
   }
}

class OutParamTest : Actor
{
   override void BeginPlay()
   {
      Super.BeginPlay();
      cls = new('DerivedClass');
   }
   override void Tick()
   {
      cls.F1(Ticker);
      cls.F2(Ticker);
      Ticker++;

      Super.Tick();
   }

   int Ticker;
   BaseClass cls;
}


This results in F1 printing the correct number: 0, 1, 2, 3 and so on, but F2 prints out some 10 digit negative number.

I had this happen in some code elsewhere and had to spend some good 20 minutes to figure out where the problem was exactly. Shouldn't this be a warning at the very least? This also sounds like a possible security concern.
Accensus
 
Joined: 11 Feb 2016

Re: 'out' can be ommited in overrides, causing silent bugs.

Postby Marisa Kirisame » Sun Nov 21, 2021 5:23 am

Rather than a warning this should be an error outright if it causes issues like those.

Especially because warnings tend to get largely ignored by most modders.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: MarisaDOOM
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: 'out' can be ommited in overrides, causing silent bugs.

Postby Accensus » Sun Nov 21, 2021 6:14 am

Wouldn't that break existing mods? Unless it only errors past a certain version, but I don't know how possible that'd be for something like this.
Accensus
 
Joined: 11 Feb 2016

Re: 'out' can be ommited in overrides, causing silent bugs.

Postby Marisa Kirisame » Sun Nov 21, 2021 6:15 pm

Sometimes you have to risk breakage to fix such a huge oversight, especially because this appears to be causing undefined behavior.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: MarisaDOOM
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: 'out' can be ommited in overrides, causing silent bugs.

Postby nova++ » Sun Nov 21, 2021 6:19 pm

Yeah, it sounds like this is enough of an issue that breaking stuff that might be using/abusing it would be a good thing.
User avatar
nova++
Real life space alien (not fake)
 
Joined: 04 Sep 2021
Discord: PM me!
Operating System: Other Linux 64-bit


Return to Bugs

Who is online

Users browsing this forum: No registered users and 2 guests