Commit 2251d558 authored by Mariusz Glebocki's avatar Mariusz Glebocki Committed by Kurt Hindenburg
Browse files

ColorScheme: fix stack-use-after-scope detected by ASAN

parent 00c56f90
......@@ -310,12 +310,13 @@ ColorEntry ColorScheme::colorEntry(int index, uint randomSeed) const
const double maxLightness = qMin(baseLightness + range.lightness / 2.0, MaxLightness);
// Use triangular distribution with peak at L=50.0.
// Dark and very light colors are less distinguishable.
const auto lightnessIntervals = (minLightness < 50.0 && 50.0 < maxLightness)
? std::initializer_list<double>{minLightness, 50.0, maxLightness}
: std::initializer_list<double>{minLightness, maxLightness};
static const auto lightnessWeightsFunc = [](double v) { return 50.0 - qAbs(v - 50.0); };
std::piecewise_linear_distribution<> lightnessDistribution(lightnessIntervals,
lightnessWeightsFunc);
std::piecewise_linear_distribution<> lightnessDistribution;
if (minLightness < 50.0 && 50.0 < maxLightness) {
lightnessDistribution = std::piecewise_linear_distribution<>({minLightness, 50.0, maxLightness}, lightnessWeightsFunc);
} else {
lightnessDistribution = std::piecewise_linear_distribution<>({minLightness, maxLightness}, lightnessWeightsFunc);
}
const double lightness = qFuzzyCompare(minLightness, maxLightness)
? baseLightness
: lightnessDistribution(randomEngine);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment