Fix more unsafe define

This commit is contained in:
Chairn 2022-06-29 23:46:28 +02:00
parent cbab1fb912
commit 96e9364fb0
8 changed files with 45 additions and 36 deletions

View file

@ -63,7 +63,7 @@ static u32 Gamma1(u32 x) { return Rot(x, 17) ^ Rot(x, 19) ^ Sh(x, 10); }
static void sha_compress(sha256_state *md, const unsigned char *buf) static void sha_compress(sha256_state *md, const unsigned char *buf)
{ {
u32 S[8], W[64], t0, t1, t; u32 S[8], W[64], t;
int i; int i;
// Copy state into S // Copy state into S
@ -80,12 +80,13 @@ static void sha_compress(sha256_state *md, const unsigned char *buf)
// Compress // Compress
#define RND(a, b, c, d, e, f, g, h, i) \ #define RND(a, b, c, d, e, f, g, h, i) \
do \
{ \ { \
t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \ u32 t0 = (h) + Sigma1(e) + Ch(e, f, g) + K[i] + W[i]; \
t1 = Sigma0(a) + Maj(a, b, c); \ u32 t1 = Sigma0(a) + Maj(a, b, c); \
d += t0; \ (d) += t0; \
h = t0 + t1; \ (h) = t0 + t1; \
} } while(0)
for(i = 0; i < 64; ++i) for(i = 0; i < 64; ++i)
{ {

View file

@ -4406,6 +4406,7 @@ void CClient::RegisterCommands()
#define CONSOLE_COMMAND(name, params, flags, callback, userdata, help) m_pConsole->Register(name, params, flags, 0, 0, help); #define CONSOLE_COMMAND(name, params, flags, callback, userdata, help) m_pConsole->Register(name, params, flags, 0, 0, help);
#include <game/ddracecommands.h> #include <game/ddracecommands.h>
#undef CONSOLE_COMMAND
} }
static CClient *CreateClient() static CClient *CreateClient()

View file

@ -82,13 +82,13 @@ bool CConfigManager::Save()
char aEscapeBuf[1024 * 2]; char aEscapeBuf[1024 * 2];
#define MACRO_CONFIG_INT(Name, ScriptName, def, min, max, flags, desc) \ #define MACRO_CONFIG_INT(Name, ScriptName, def, min, max, flags, desc) \
if((flags)&CFGFLAG_SAVE && g_Config.m_##Name != def) \ if((flags)&CFGFLAG_SAVE && g_Config.m_##Name != (def)) \
{ \ { \
str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); \ str_format(aLineBuf, sizeof(aLineBuf), "%s %i", #ScriptName, g_Config.m_##Name); \
WriteLine(aLineBuf); \ WriteLine(aLineBuf); \
} }
#define MACRO_CONFIG_COL(Name, ScriptName, def, flags, desc) \ #define MACRO_CONFIG_COL(Name, ScriptName, def, flags, desc) \
if((flags)&CFGFLAG_SAVE && g_Config.m_##Name != def) \ if((flags)&CFGFLAG_SAVE && g_Config.m_##Name != (def)) \
{ \ { \
str_format(aLineBuf, sizeof(aLineBuf), "%s %u", #ScriptName, g_Config.m_##Name); \ str_format(aLineBuf, sizeof(aLineBuf), "%s %u", #ScriptName, g_Config.m_##Name); \
WriteLine(aLineBuf); \ WriteLine(aLineBuf); \

View file

@ -132,19 +132,25 @@ int CHuffman::Compress(const void *pInput, int InputSize, void *pOutput, int Out
{ {
// this macro loads a symbol for a byte into bits and bitcount // this macro loads a symbol for a byte into bits and bitcount
#define HUFFMAN_MACRO_LOADSYMBOL(Sym) \ #define HUFFMAN_MACRO_LOADSYMBOL(Sym) \
Bits |= m_aNodes[Sym].m_Bits << Bitcount; \ do \
Bitcount += m_aNodes[Sym].m_NumBits; { \
Bits |= m_aNodes[Sym].m_Bits << Bitcount; \
Bitcount += m_aNodes[Sym].m_NumBits; \
} while(0)
// this macro writes the symbol stored in bits and bitcount to the dst pointer // this macro writes the symbol stored in bits and bitcount to the dst pointer
#define HUFFMAN_MACRO_WRITE() \ #define HUFFMAN_MACRO_WRITE() \
while(Bitcount >= 8) \ do \
{ \ { \
*pDst++ = (unsigned char)(Bits & 0xff); \ while(Bitcount >= 8) \
if(pDst == pDstEnd) \ { \
return -1; \ *pDst++ = (unsigned char)(Bits & 0xff); \
Bits >>= 8; \ if(pDst == pDstEnd) \
Bitcount -= 8; \ return -1; \
} Bits >>= 8; \
Bitcount -= 8; \
} \
} while(0)
// setup buffer pointers // setup buffer pointers
const unsigned char *pSrc = (const unsigned char *)pInput; const unsigned char *pSrc = (const unsigned char *)pInput;
@ -165,23 +171,23 @@ int CHuffman::Compress(const void *pInput, int InputSize, void *pOutput, int Out
while(pSrc != pSrcEnd) while(pSrc != pSrcEnd)
{ {
// {B} load the symbol // {B} load the symbol
HUFFMAN_MACRO_LOADSYMBOL(Symbol) HUFFMAN_MACRO_LOADSYMBOL(Symbol);
// {C} fetch next symbol, this is done here because it will reduce dependency in the code // {C} fetch next symbol, this is done here because it will reduce dependency in the code
Symbol = *pSrc++; Symbol = *pSrc++;
// {B} write the symbol loaded at // {B} write the symbol loaded at
HUFFMAN_MACRO_WRITE() HUFFMAN_MACRO_WRITE();
} }
// write the last symbol loaded from {C} or {A} in the case of only 1 byte input buffer // write the last symbol loaded from {C} or {A} in the case of only 1 byte input buffer
HUFFMAN_MACRO_LOADSYMBOL(Symbol) HUFFMAN_MACRO_LOADSYMBOL(Symbol);
HUFFMAN_MACRO_WRITE() HUFFMAN_MACRO_WRITE();
} }
// write EOF symbol // write EOF symbol
HUFFMAN_MACRO_LOADSYMBOL(HUFFMAN_EOF_SYMBOL) HUFFMAN_MACRO_LOADSYMBOL(HUFFMAN_EOF_SYMBOL);
HUFFMAN_MACRO_WRITE() HUFFMAN_MACRO_WRITE();
// write out the last bits // write out the last bits
*pDst++ = Bits; *pDst++ = Bits;

View file

@ -32,6 +32,7 @@ CChat::CChat()
#define CHAT_COMMAND(name, params, flags, callback, userdata, help) RegisterCommand(name, params, flags, help); #define CHAT_COMMAND(name, params, flags, callback, userdata, help) RegisterCommand(name, params, flags, help);
#include <game/ddracechat.h> #include <game/ddracechat.h>
#undef CHAT_COMMAND
std::sort(m_vCommands.begin(), m_vCommands.end()); std::sort(m_vCommands.begin(), m_vCommands.end());
m_Mode = MODE_NONE; m_Mode = MODE_NONE;

View file

@ -44,7 +44,7 @@ public:
CTuningParams() CTuningParams()
{ {
const float TicksPerSecond = 50.0f; const float TicksPerSecond = 50.0f;
#define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) m_##Name.Set((int)(Value * 100.0f)); #define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) m_##Name.Set((int)((Value)*100.0f));
#include "tuning.h" #include "tuning.h"
#undef MACRO_TUNING_PARAM #undef MACRO_TUNING_PARAM
} }

View file

@ -78,7 +78,7 @@ int CMapBugs::Update(const char *pBug)
int Bug = -1; int Bug = -1;
if(false) {} // NOLINT(readability-simplify-boolean-expr) if(false) {} // NOLINT(readability-simplify-boolean-expr)
#define MAPBUG(constname, string) \ #define MAPBUG(constname, string) \
else if(str_comp(pBug, string) == 0) { Bug = constname; } else if(str_comp(pBug, string) == 0) { Bug = (constname); }
#include "mapbugs_list.h" #include "mapbugs_list.h"
#undef MAPBUG #undef MAPBUG
if(Bug == -1) if(Bug == -1)

View file

@ -256,18 +256,18 @@ void CGameContext::ConRules(IConsole::IResult *pResult, void *pUserData)
"Be nice."); "Be nice.");
Printed = true; Printed = true;
} }
#define _RL(n) g_Config.m_SvRulesLine##n #define GET_SERVER_RULE_LINE(n) g_Config.m_SvRulesLine##n
char *pRuleLines[] = { char *pRuleLines[] = {
_RL(1), GET_SERVER_RULE_LINE(1),
_RL(2), GET_SERVER_RULE_LINE(2),
_RL(3), GET_SERVER_RULE_LINE(3),
_RL(4), GET_SERVER_RULE_LINE(4),
_RL(5), GET_SERVER_RULE_LINE(5),
_RL(6), GET_SERVER_RULE_LINE(6),
_RL(7), GET_SERVER_RULE_LINE(7),
_RL(8), GET_SERVER_RULE_LINE(8),
_RL(9), GET_SERVER_RULE_LINE(9),
_RL(10), GET_SERVER_RULE_LINE(10),
}; };
for(auto &pRuleLine : pRuleLines) for(auto &pRuleLine : pRuleLines)
{ {