Possible NPD with frontsector of line_t
Doom uses a structure called line to define the structure
of the maps. It is assumed that each line always has a front sector
and an optional back sector. If a line has only the front sector,
then it is a one-sided line. If it has a back sector, then it is a
two-sided line. Line structure is represented in the code with
struct line_t
:
In the code, dereferencing the
backsector
is usually preceded by a check that
backsector
is not a null pointer. There are no such checks for the
frontsector
. For example, this is illustrated in
P_GroupLines
:
However, when initializing line definitions,
frontsector
can be assigned a null pointer in
P_LoadLineDefs
:
Here,
mld
is the
raw data read from the file and
ld
is the
line_t
being constructed. When
sidenum[0]
is -1
,
null pointer is written to
ld.frontsector
.
Solutions in existing projects
Other source ports handle this situation differently. For example, Mocha Doom issues a warning in one case:
In the
other case
it sets
null
as
the
frontsector
value:
Delphi Doom
also issues a warning and sets another sector as the
frontsector
:
Our solution and Void Safety
Brie Doom’s source code is written with Void Safety enabled, so we
have to decide if
frontsector
should indeed be
attached
and assigning
Void
to it
should be banned, or should it be
detached
and all dereferences will be preceded with checking if
frontsector
is not
Void
. We
cannot simply ignore this problem by assigning
Void
in
one place and just assuming that it should not be
Void
in
other places.
As a temporary solution for phase 1 we decided to leave
frontsector
as
detached
to preserve the original behaviour. All dereferences of
frontsector
first check that it is not
Void
.
Example in
P_GroupLines
:
This solution is not ideal as it increases the verbosity of the
code. Each access to
frontsector
has to be surrounded by a
check
.
In fact, this solution does not solve the real problem. What should the game do with a malformed map data? Maybe it should refuse working with such incorrect data altogether, maybe not. Changing this behaviour is left for phase 2 where we will revisit this problem again.