mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-03-19 09:11:41 +00:00
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).
462404af67
This commit is contained in:
parent
da119a30c6
commit
c8f09d4ac7
1 changed files with 6 additions and 0 deletions
|
@ -58,6 +58,11 @@ public:
|
|||
};
|
||||
|
||||
ID_INLINE idRegister::idRegister( void ) {
|
||||
enabled = false;
|
||||
type = -1;
|
||||
regCount = 0;
|
||||
memset(regs, 0, sizeof(regs));
|
||||
var = NULL;
|
||||
}
|
||||
|
||||
ID_INLINE idRegister::idRegister( const char *p, int t ) {
|
||||
|
@ -65,6 +70,7 @@ ID_INLINE idRegister::idRegister( const char *p, int t ) {
|
|||
type = t;
|
||||
assert( t >= 0 && t < NUMTYPES );
|
||||
regCount = REGCOUNT[t];
|
||||
memset(regs, 0, sizeof(regs));
|
||||
enabled = ( type == STRING ) ? false : true;
|
||||
var = NULL;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue