Page MenuHomeFeedback Tracker

Enforce script allows access to uninitialized variables during class inheritance - segfaulting in Linux
Assigned, NormalPublic

Description

While using class inheritance in mods, it is possible to create a child class inherited from a base class, that allows to access class variables from the base class without initializing them, especially without calling the constructor of the base class using super.

The following code would just work fine in windows, but results in segfaults of the game in linux due to sane memory handling. Under windows the behavior is actually not defined, but windows also doesn't care about its memory.

class BaseClass {
   int foo;
}
class ChildClass : BaseClass {
  void ChildClass(int bar) {
    foo = bar;
  }
}

I know that it is hard to check for all variables, but I think enforcing to use super in the constructor of an inherited class would be a good start. There are way too many modules out there that cause segfaults due to such issues.

Details

Severity
None
Resolution
Open
Reproducibility
Always
Operating System
Linux x64
Operating System Version
Debian Bookworm
Category
General
Steps To Reproduce

See description

Event Timeline

bzed created this task.Mar 6 2025, 6:35 PM
Geez changed the task status from New to Assigned.Mar 7 2025, 10:53 AM
lava76 added a subscriber: lava76.Wed, Mar 19, 2:58 PM

There is no such thing as an uninitialized variable in EnforceScript. All variables are initialized to a default on declaration if there is no direct assignment (bool false, float 0.0, int 0 , string "", vector "0 0 0", anything other NULL), and this is a core language feature. Think Java/C#, not C/C++. The above example is valid code and completely fine. If that indeed crashes under Linux(?), that's a bug that needs to be fixed on that platform.

bzed added a comment.Wed, Mar 19, 4:37 PM

@lava76 indeed that case crashes on linux. I've debugged that in an older version of https://steamcommunity.com/sharedfiles/filedetails/?id=3381664818 and the mod was rewritten to use proper constructors and super calls as you would do it in c++, which fixed the segfault. The original constructor was in the form as mentioned above, rather simple, some variables in the child class, and the access to the base class segfaulted.