1
0
Fork 0

Fix: 'Suspicious add with sizeof' CodeQL warnings

pull/12438/head
Rubidium 2024-04-06 20:25:25 +02:00
parent 97bea563d7
commit a2a5f21c19
1 changed files with 24 additions and 24 deletions

View File

@ -810,34 +810,34 @@ struct FrametimeGraphWindow : Window {
/* Determine horizontal scale based on period covered by 60 points /* Determine horizontal scale based on period covered by 60 points
* (slightly less than 2 seconds at full game speed) */ * (slightly less than 2 seconds at full game speed) */
struct ScaleDef { TimingMeasurement range; int scale; }; struct ScaleDef { TimingMeasurement range; int scale; };
static const ScaleDef hscales[] = { static const std::array hscales{
{ TIMESTAMP_PRECISION * 120, 60 }, ScaleDef{ TIMESTAMP_PRECISION * 120, 60 },
{ TIMESTAMP_PRECISION * 10, 20 }, ScaleDef{ TIMESTAMP_PRECISION * 10, 20 },
{ TIMESTAMP_PRECISION * 5, 10 }, ScaleDef{ TIMESTAMP_PRECISION * 5, 10 },
{ TIMESTAMP_PRECISION * 3, 4 }, ScaleDef{ TIMESTAMP_PRECISION * 3, 4 },
{ TIMESTAMP_PRECISION * 1, 2 }, ScaleDef{ TIMESTAMP_PRECISION * 1, 2 },
}; };
for (const ScaleDef *sc = hscales; sc < hscales + lengthof(hscales); sc++) { for (auto sc : hscales) {
if (range < sc->range) this->horizontal_scale = sc->scale; if (range < sc.range) this->horizontal_scale = sc.scale;
} }
} }
void SelectVerticalScale(TimingMeasurement range) void SelectVerticalScale(TimingMeasurement range)
{ {
/* Determine vertical scale based on peak value (within the horizontal scale + a bit) */ /* Determine vertical scale based on peak value (within the horizontal scale + a bit) */
static const TimingMeasurement vscales[] = { static const std::array vscales = {
TIMESTAMP_PRECISION * 100, TimingMeasurement{ TIMESTAMP_PRECISION * 100 },
TIMESTAMP_PRECISION * 10, TimingMeasurement{ TIMESTAMP_PRECISION * 10 },
TIMESTAMP_PRECISION * 5, TimingMeasurement{ TIMESTAMP_PRECISION * 5 },
TIMESTAMP_PRECISION, TimingMeasurement{ TIMESTAMP_PRECISION },
TIMESTAMP_PRECISION / 2, TimingMeasurement{ TIMESTAMP_PRECISION / 2 },
TIMESTAMP_PRECISION / 5, TimingMeasurement{ TIMESTAMP_PRECISION / 5 },
TIMESTAMP_PRECISION / 10, TimingMeasurement{ TIMESTAMP_PRECISION / 10 },
TIMESTAMP_PRECISION / 50, TimingMeasurement{ TIMESTAMP_PRECISION / 50 },
TIMESTAMP_PRECISION / 200, TimingMeasurement{ TIMESTAMP_PRECISION / 200 },
}; };
for (const TimingMeasurement *sc = vscales; sc < vscales + lengthof(vscales); sc++) { for (auto sc : vscales) {
if (range < *sc) this->vertical_scale = (int)*sc; if (range < sc) this->vertical_scale = static_cast<int>(sc);
} }
} }
@ -1066,15 +1066,15 @@ void ConPrintFramerate()
}; };
std::string ai_name_buf; std::string ai_name_buf;
static const PerformanceElement rate_elements[] = { PFE_GAMELOOP, PFE_DRAWING, PFE_VIDEO }; static const std::array rate_elements = { PFE_GAMELOOP, PFE_DRAWING, PFE_VIDEO };
bool printed_anything = false; bool printed_anything = false;
for (const PerformanceElement *e = rate_elements; e < rate_elements + lengthof(rate_elements); e++) { for (auto rate_element : rate_elements) {
auto &pf = _pf_data[*e]; auto &pf = _pf_data[rate_element];
if (pf.num_valid == 0) continue; if (pf.num_valid == 0) continue;
IConsolePrint(TC_GREEN, "{} rate: {:.2f}fps (expected: {:.2f}fps)", IConsolePrint(TC_GREEN, "{} rate: {:.2f}fps (expected: {:.2f}fps)",
MEASUREMENT_NAMES[*e], MEASUREMENT_NAMES[rate_element],
pf.GetRate(), pf.GetRate(),
pf.expected_rate); pf.expected_rate);
printed_anything = true; printed_anything = true;