Sitelet https://github.com/stepcode/stepcode/pull/486
Skip to content

Initialise two members that are read before they are written - #486

Open
attixray wants to merge 2 commits into
stepcode:developfrom
attixray:sc-fix-uninitialized-member-reads
Open

Initialise two members that are read before they are written#486
attixray wants to merge 2 commits into
stepcode:developfrom
attixray:sc-fix-uninitialized-member-reads

Conversation

@attixray

Copy link
Copy Markdown

Two independent uninitialised reads, both long-standing.

STEPnode::_null has no default. STEPnode has no constructor, so a node built by a subclass that does not assign it starts out with whatever was on the heap, and is_null() then answers at random. This adds a STEPnode constructor that starts nodes null, and makes EntityNode::StrToVal() / ::STEPread() set it per outcome — they resolve an entity reference and should report null exactly when the reference did not resolve.

TypeDescriptor::_altname is a char _altname[BUFSIZ+1] that both constructors leave untouched, while AltName() and the Name() fallback read it as a C string. Terminating it on construction makes the "no alternate name" case deterministic.

Two commits, one per member.

Attila Prokai added 2 commits August 21, 2026 19:50
STEPnode::_null had no default: STEPnode has no constructor, so a node built
by a subclass that does not assign it starts out with whatever was on the
heap, and is_null() then answers at random. Give STEPnode a constructor that
starts nodes null.

EntityNode::StrToVal() and ::STEPread() additionally have to set it per
outcome - they resolve an entity reference and must report null exactly when
the reference did not resolve. Before this, a node whose reference failed to
resolve could still report itself non-null.
_altname is a char[BUFSIZ+1] that neither constructor touches, so CurrName()
and the AltNameOf paths can read uninitialised heap until something calls
AltName(). Start it empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant