mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Run PVS-STUDIO analyzer
Fix issues after a run of PVS-STUDIO analyzer. Mainly false positives but warnings are anyhow useful to point out not very readable code. Noteworthy is the memset() one, where PVS prefers ss-2 instead of stack. This is because memeset() could be optimized away by the compiler when using 'stack', due to stack being a local variable no more used after memset. This should normally not happen, but when it happens it leads to very sublte and difficult to find bug, so better to be safe than sorry. No functional change.
This commit is contained in:
parent
83e19fbed5
commit
ca38358574
5 changed files with 16 additions and 12 deletions
|
@ -47,4 +47,5 @@ int main(int argc, char* argv[]) {
|
||||||
UCI::loop(argc, argv);
|
UCI::loop(argc, argv);
|
||||||
|
|
||||||
Threads.exit();
|
Threads.exit();
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,10 +58,11 @@ namespace {
|
||||||
|
|
||||||
if (Checks && !pos.gives_check(m, *ci))
|
if (Checks && !pos.gives_check(m, *ci))
|
||||||
return moveList;
|
return moveList;
|
||||||
|
else
|
||||||
|
(void)ci; // Silence a warning under MSVC
|
||||||
|
|
||||||
*moveList++ = m;
|
*moveList++ = m;
|
||||||
|
return moveList;
|
||||||
return (void)ci, moveList; // Silence a warning under MSVC
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,8 +83,10 @@ namespace {
|
||||||
// that's not already included in the queen promotion.
|
// that's not already included in the queen promotion.
|
||||||
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq))
|
if (Type == QUIET_CHECKS && (StepAttacksBB[W_KNIGHT][to] & ci->ksq))
|
||||||
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT);
|
*moveList++ = make<PROMOTION>(to - Delta, to, KNIGHT);
|
||||||
|
else
|
||||||
|
(void)ci; // Silence a warning under MSVC
|
||||||
|
|
||||||
return (void)ci, moveList; // Silence a warning under MSVC
|
return moveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,8 @@ struct Stats {
|
||||||
|
|
||||||
void update(Piece pc, Square to, Value v) {
|
void update(Piece pc, Square to, Value v) {
|
||||||
|
|
||||||
table[pc][to] -= table[pc][to] * std::min(abs(int(v)), 512) / 512;
|
table[pc][to] -= table[pc][to] * std::min(abs(v), 512) / 512;
|
||||||
table[pc][to] += int(v) * 64;
|
table[pc][to] += v * 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -341,7 +341,7 @@ namespace {
|
||||||
Move easyMove = EasyMove.get(pos.key());
|
Move easyMove = EasyMove.get(pos.key());
|
||||||
EasyMove.clear();
|
EasyMove.clear();
|
||||||
|
|
||||||
std::memset(stack, 0, 5 * sizeof(Stack));
|
std::memset(ss-2, 0, 5 * sizeof(Stack));
|
||||||
|
|
||||||
depth = DEPTH_ZERO;
|
depth = DEPTH_ZERO;
|
||||||
BestMoveChanges = 0;
|
BestMoveChanges = 0;
|
||||||
|
|
10
src/uci.cpp
10
src/uci.cpp
|
@ -90,11 +90,11 @@ namespace {
|
||||||
|
|
||||||
// Read option name (can contain spaces)
|
// Read option name (can contain spaces)
|
||||||
while (is >> token && token != "value")
|
while (is >> token && token != "value")
|
||||||
name += string(" ", !name.empty()) + token;
|
name += string(" ", name.empty() ? 0 : 1) + token;
|
||||||
|
|
||||||
// Read option value (can contain spaces)
|
// Read option value (can contain spaces)
|
||||||
while (is >> token)
|
while (is >> token)
|
||||||
value += string(" ", !value.empty()) + token;
|
value += string(" ", value.empty() ? 0 : 1) + token;
|
||||||
|
|
||||||
if (Options.count(name))
|
if (Options.count(name))
|
||||||
Options[name] = value;
|
Options[name] = value;
|
||||||
|
@ -126,8 +126,8 @@ namespace {
|
||||||
else if (token == "nodes") is >> limits.nodes;
|
else if (token == "nodes") is >> limits.nodes;
|
||||||
else if (token == "movetime") is >> limits.movetime;
|
else if (token == "movetime") is >> limits.movetime;
|
||||||
else if (token == "mate") is >> limits.mate;
|
else if (token == "mate") is >> limits.mate;
|
||||||
else if (token == "infinite") limits.infinite = true;
|
else if (token == "infinite") limits.infinite = 1;
|
||||||
else if (token == "ponder") limits.ponder = true;
|
else if (token == "ponder") limits.ponder = 1;
|
||||||
|
|
||||||
Threads.start_thinking(pos, limits, SetupStates);
|
Threads.start_thinking(pos, limits, SetupStates);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ void UCI::loop(int argc, char* argv[]) {
|
||||||
Threads.main()->notify_one(); // Could be sleeping
|
Threads.main()->notify_one(); // Could be sleeping
|
||||||
}
|
}
|
||||||
else if (token == "ponderhit")
|
else if (token == "ponderhit")
|
||||||
Search::Limits.ponder = false; // Switch to normal search
|
Search::Limits.ponder = 0; // Switch to normal search
|
||||||
|
|
||||||
else if (token == "uci")
|
else if (token == "uci")
|
||||||
sync_cout << "id name " << engine_info(true)
|
sync_cout << "id name " << engine_info(true)
|
||||||
|
|
Loading…
Add table
Reference in a new issue