From ddaa0c8f704c876d8c9c7f4c889a489c86e5773d Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Mon, 17 Dec 2012 00:54:40 +0100 Subject: [PATCH] Fix crash when loading mc_underground map it was because in Window.cpp/h a lot of pointers were castet to ints.. if such abomination is done at least use intptr_t... --- neo/ui/Window.cpp | 35 +++++++++++++++++++++-------------- neo/ui/Window.h | 19 ++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/neo/ui/Window.cpp b/neo/ui/Window.cpp index 2d14e003..b3f0c194 100644 --- a/neo/ui/Window.cpp +++ b/neo/ui/Window.cpp @@ -2026,10 +2026,11 @@ void idWindow::PostParse() idWindow::GetWinVarOffset ================ */ -int idWindow::GetWinVarOffset( idWinVar* wv, drawWin_t* owner ) +intptr_t idWindow::GetWinVarOffset( idWinVar* wv, drawWin_t* owner ) { // RB: 64 bit fixes, changed oldschool offsets using ptrdiff_t - int ret = -1; + // DG: => also return intptr_t.. + intptr_t ret = -1; if( wv == &rect ) { @@ -3124,9 +3125,9 @@ wexpOp_t* idWindow::ExpressionOp() idWindow::EmitOp ================ */ - -int idWindow::EmitOp( int a, int b, wexpOpType_t opType, wexpOp_t** opp ) -{ +// DG: a, b and the return value are really pointers, so use intptr_t +intptr_t idWindow::EmitOp( intptr_t a, intptr_t b, wexpOpType_t opType, wexpOp_t** opp ) +{ // DG end wexpOp_t* op; /* // optimize away identity operations @@ -3178,9 +3179,11 @@ int idWindow::EmitOp( int a, int b, wexpOpType_t opType, wexpOp_t** opp ) idWindow::ParseEmitOp ================ */ -int idWindow::ParseEmitOp( idTokenParser* src, int a, wexpOpType_t opType, int priority, wexpOp_t** opp ) +// DG: a, b and the return value are really pointers, so use intptr_t +intptr_t idWindow::ParseEmitOp( idTokenParser* src, intptr_t a, wexpOpType_t opType, int priority, wexpOp_t** opp ) { - int b = ParseExpressionPriority( src, priority ); + intptr_t b = ParseExpressionPriority( src, priority ); +// DG end return EmitOp( a, b, opType, opp ); } @@ -3192,8 +3195,9 @@ idWindow::ParseTerm Returns a register index ================= */ -int idWindow::ParseTerm( idTokenParser* src, idWinVar* var, int component ) -{ +// DG: component and the return value are really pointers, so use intptr_t +intptr_t idWindow::ParseTerm( idTokenParser* src, idWinVar* var, intptr_t component ) +{ // DG end idToken token; // RB: 64 bit fixes, changed int to intptr_t intptr_t a, b; @@ -3315,10 +3319,11 @@ Returns a register index ================= */ #define TOP_PRIORITY 4 -int idWindow::ParseExpressionPriority( idTokenParser* src, int priority, idWinVar* var, int component ) +// DG: a, component and the return value are really pointers, so use intptr_t +intptr_t idWindow::ParseExpressionPriority( idTokenParser* src, int priority, idWinVar* var, intptr_t component ) { idToken token; - int a; + intptr_t a; if( priority == 0 ) { @@ -3389,7 +3394,8 @@ int idWindow::ParseExpressionPriority( idTokenParser* src, int priority, idWinVa if( priority == 4 && token == "?" ) { wexpOp_t* oop = NULL; - int o = ParseEmitOp( src, a, WOP_TYPE_COND, priority, &oop ); + intptr_t o = ParseEmitOp( src, a, WOP_TYPE_COND, priority, &oop ); + // DG end if( !src->ReadToken( &token ) ) { return o; @@ -3417,8 +3423,9 @@ idWindow::ParseExpression Returns a register index ================ */ -int idWindow::ParseExpression( idTokenParser* src, idWinVar* var, int component ) -{ +// DG: component and the return value are really pointers, so use intptr_t +intptr_t idWindow::ParseExpression( idTokenParser* src, idWinVar* var, intptr_t component ) +{ // DG end return ParseExpressionPriority( src, TOP_PRIORITY, var ); } diff --git a/neo/ui/Window.h b/neo/ui/Window.h index 60934d11..71825e6d 100644 --- a/neo/ui/Window.h +++ b/neo/ui/Window.h @@ -248,8 +248,9 @@ public: idStr* GetStrPtrByName( const char* _name ); virtual idWinVar* GetWinVarByName( const char* _name, bool winLookup = false, drawWin_t** owner = NULL ); - - int GetWinVarOffset( idWinVar* wv, drawWin_t* dw ); + // DG: the return value is a pointer, so use intptr_t + intptr_t GetWinVarOffset( idWinVar* wv, drawWin_t* dw ); + // DG end float GetMaxCharHeight(); float GetMaxCharWidth(); void SetFont(); @@ -326,7 +327,9 @@ public: bool RunScript( int n ); bool RunScriptList( idGuiScriptList* src ); void SetRegs( const char* key, const char* val ); - int ParseExpression( idTokenParser* src, idWinVar* var = NULL, int component = 0 ); + // DG: component and the return value are really pointers, so use intptr_t + intptr_t ParseExpression( idTokenParser* src, idWinVar* var = NULL, intptr_t component = 0 ); + // DG end int ExpressionConstant( float f ); idRegisterList* RegList() { @@ -385,10 +388,12 @@ protected: int ExpressionTemporary(); wexpOp_t* ExpressionOp(); - int EmitOp( int a, int b, wexpOpType_t opType, wexpOp_t** opp = NULL ); - int ParseEmitOp( idTokenParser* src, int a, wexpOpType_t opType, int priority, wexpOp_t** opp = NULL ); - int ParseTerm( idTokenParser* src, idWinVar* var = NULL, int component = 0 ); - int ParseExpressionPriority( idTokenParser* src, int priority, idWinVar* var = NULL, int component = 0 ); + // DG: a, b, component and the return values are really pointers, so use intptr_t + intptr_t EmitOp( intptr_t a, intptr_t b, wexpOpType_t opType, wexpOp_t** opp = NULL ); + intptr_t ParseEmitOp( idTokenParser* src, intptr_t a, wexpOpType_t opType, int priority, wexpOp_t** opp = NULL ); + intptr_t ParseTerm( idTokenParser* src, idWinVar* var = NULL, intptr_t component = 0 ); + intptr_t ParseExpressionPriority( idTokenParser* src, int priority, idWinVar* var = NULL, intptr_t component = 0 ); + // DG end void EvaluateRegisters( float* registers ); void SaveExpressionParseState(); void RestoreExpressionParseState();