diff options
author | Torbjörn Andersson | 2013-05-31 19:30:36 +0200 |
---|---|---|
committer | Torbjörn Andersson | 2013-05-31 19:30:36 +0200 |
commit | f7099c57d1bd2cbed983596abaee85c7dc9194c3 (patch) | |
tree | 72b404df92cd5b6539071913abdc7f496853aef7 | |
parent | f38c7d76efe277c9dc3b48ab666abcbebeb73373 (diff) | |
download | scummvm-rg350-f7099c57d1bd2cbed983596abaee85c7dc9194c3.tar.gz scummvm-rg350-f7099c57d1bd2cbed983596abaee85c7dc9194c3.tar.bz2 scummvm-rg350-f7099c57d1bd2cbed983596abaee85c7dc9194c3.zip |
NEVERHOOD: Made multi-line function-line macros safer
Wrapped the code in the SetUpdateHandler(), SetMessageHandler(),
SetSpriteUpdate(), SetFilterX(), SetFilterY() and NextState()
macros in "do { ... } while (0)". Otherwise you may fool yourself
because in "if (condition) macro();" the "if" will only cover the
first statement of the macro.
CID 1022340, 1022341, 1022342, 1022343
-rw-r--r-- | engines/neverhood/entity.h | 16 | ||||
-rw-r--r-- | engines/neverhood/sprite.h | 27 |
2 files changed, 33 insertions, 10 deletions
diff --git a/engines/neverhood/entity.h b/engines/neverhood/entity.h index fb8941ae43..cba1bb9a7f 100644 --- a/engines/neverhood/entity.h +++ b/engines/neverhood/entity.h @@ -60,14 +60,18 @@ protected: // TODO: Disable heavy debug stuff in release mode #define SetUpdateHandler(handler) \ - _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); \ - debug(5, "SetUpdateHandler(" #handler ")"); \ - _updateHandlerCbName = #handler + do { \ + _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); \ + debug(5, "SetUpdateHandler(" #handler ")"); \ + _updateHandlerCbName = #handler; \ + } while (0) #define SetMessageHandler(handler) \ - _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler); \ - debug(5, "SetMessageHandler(" #handler ")"); \ - _messageHandlerCbName = #handler + do { \ + _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler); \ + debug(5, "SetMessageHandler(" #handler ")"); \ + _messageHandlerCbName = #handler; \ + } while (0) const uint kMaxSoundResources = 16; diff --git a/engines/neverhood/sprite.h b/engines/neverhood/sprite.h index 80da1768bd..1d17bf0e70 100644 --- a/engines/neverhood/sprite.h +++ b/engines/neverhood/sprite.h @@ -30,9 +30,24 @@ namespace Neverhood { -#define SetSpriteUpdate(callback) _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback); debug(2, "SetSpriteUpdate(" #callback ")"); _spriteUpdateCbName = #callback -#define SetFilterX(callback) _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback); debug(2, "SetFilterX(" #callback ")") -#define SetFilterY(callback) _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback); debug(2, "SetFilterY(" #callback ")") +#define SetSpriteUpdate(callback) \ + do { \ + _spriteUpdateCb = static_cast <void (Sprite::*)(void)> (callback); \ + debug(2, "SetSpriteUpdate(" #callback ")"); \ + _spriteUpdateCbName = #callback; \ + } while (0) + +#define SetFilterX(callback) \ + do { \ + _filterXCb = static_cast <int16 (Sprite::*)(int16)> (callback); \ + debug(2, "SetFilterX(" #callback ")"); \ + } while (0) + +#define SetFilterY(callback) \ + do { \ + _filterYCb = static_cast <int16 (Sprite::*)(int16)> (callback); \ + debug(2, "SetFilterY(" #callback ")"); \ + } while (0) const int16 kDefPosition = -32768; @@ -113,7 +128,11 @@ protected: #define AnimationCallback(callback) static_cast <void (AnimatedSprite::*)()> (callback) #define GotoState(callback) gotoState(static_cast <void (AnimatedSprite::*)()> (callback)) -#define NextState(callback) _nextStateCb = static_cast <void (AnimatedSprite::*)(void)> (callback); debug(2, "NextState(" #callback ")"); _nextStateCbName = #callback +#define NextState(callback) \ + do { \ + _nextStateCb = static_cast <void (AnimatedSprite::*)(void)> (callback); \ + debug(2, "NextState(" #callback ")"); _nextStateCbName = #callback; \ + } while (0) #define FinalizeState(callback) setFinalizeState(static_cast <void (AnimatedSprite::*)()> (callback)); const int STICK_LAST_FRAME = -2; |