Skip to content

Commit c8f09d4

Browse files
committed
Initialize all idRegister class members in constructors
in SkinDeep regs not being initialized caused random crashes (in dhewm3 I haven't seen that so far, but fixing this won't hurt). From SkinDeep commit message: In idRegister::SetToRegs() at `registers[ regs[ i ] ] = v[i];` regs[i] contained values like 21845 or 22010 or 32272, even though the static registers array that's written to there only holds 4096 elements (it's `static float regs[MAX_EXPRESSION_REGISTERS];` from `idWindow::EvalRegs()`). So it overwrites other data, likely other global variables, like `gameLocal.entities[4967]`, that now contain garbage and next time someone tries to use them, bad things happen. In this case, if someone tries to dereference gameLocal.entities[i] and the pointer at i contains garbage, there's a segfault (crash). DanielGibson/SkinDeep@462404a
1 parent da119a3 commit c8f09d4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

neo/ui/RegExp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,19 @@ class idRegister {
5858
};
5959

6060
ID_INLINE idRegister::idRegister( void ) {
61+
enabled = false;
62+
type = -1;
63+
regCount = 0;
64+
memset(regs, 0, sizeof(regs));
65+
var = NULL;
6166
}
6267

6368
ID_INLINE idRegister::idRegister( const char *p, int t ) {
6469
name = p;
6570
type = t;
6671
assert( t >= 0 && t < NUMTYPES );
6772
regCount = REGCOUNT[t];
73+
memset(regs, 0, sizeof(regs));
6874
enabled = ( type == STRING ) ? false : true;
6975
var = NULL;
7076
};

0 commit comments

Comments
 (0)