17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-08 21:00:03 +01:00

fix: the bugs and vulnerabilities SonarCloud reports on PR #216

This commit is contained in:
2026-11-07 22:11:08 +01:00
parent 8e85def98f
commit 7667e5b2ec
65 changed files with 910 additions and 121 deletions

View File

@@ -1980,14 +1980,16 @@ std::optional<lay_result> lay_on(lay_request const &Request)
auto const step{std::max(0.5, radius * glm::radians(2.0))};
double low{0.0};
double high{-1.0};
for (auto arc{step}; arc < 2.0 * kPi * radius; arc += step)
auto tried{step};
while (tried < 2.0 * kPi * radius)
{
if (miss(arc)[0] <= 0.0)
if (miss(tried)[0] <= 0.0)
{
high = arc;
high = tried;
break;
}
low = arc;
low = tried;
tried += step;
}
if (high < 0.0)
return std::nullopt;

View File

@@ -100,6 +100,8 @@ std::uint64_t clip::texture(double const Seconds)
long long total{0};
for (auto const delay : frames.delays)
total += delay;
if (total <= 0)
total = 1; // no frame with a delay: the clip stands still
auto time{static_cast<long long>(std::floor(Seconds * 1000.0)) % total};
int index{0};
while (index + 1 < static_cast<int>(frames.delays.size()) && time >= frames.delays[index])

View File

@@ -157,12 +157,14 @@ switch_report check(std::vector<track_point> const &Main, std::vector<track_poin
auto const margin{std::min(1.0, length * 0.25)};
result.first = sign * curvature_at(Track, Track.front().station + margin);
result.last = sign * curvature_at(Track, finish - margin);
for (auto s{Track.front().station + margin}; s <= finish - margin + 1e-9; s += 0.5)
auto s{Track.front().station + margin};
while (s <= finish - margin + 1e-9)
{
auto const curvature{sign * curvature_at(Track, s)};
result.low = std::min(result.low, curvature);
result.high = std::max(result.high, curvature);
result.sharpest = std::max(result.sharpest, std::abs(curvature));
s += 0.5;
}
return result;
};
@@ -222,12 +224,14 @@ slip_report check_slip(std::vector<std::vector<track_point>> const &Tracks, std:
auto const along = [&](std::vector<track_point> const &Track) {
span result;
auto const margin{std::min(1.0, (Track.back().station - Track.front().station) * 0.25)};
for (auto s{Track.front().station + margin}; s <= Track.back().station - margin + 1e-9; s += 0.5)
auto s{Track.front().station + margin};
while (s <= Track.back().station - margin + 1e-9)
{
auto const curvature{sign * curvature_at(Track, s)};
result.low = std::min(result.low, curvature);
result.high = std::max(result.high, curvature);
result.sharpest = std::max(result.sharpest, std::abs(curvature));
s += 0.5;
}
return result;
};