From 2ef8841983738fa5d2d65cbe92614c90e9ebdb0f Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Thu, 30 Jul 2026 10:56:06 +0200 Subject: [PATCH] Azimuthal integration: keep the low Q limit below the maximum Making the high limit optional removed the implicit upper bound on the low one (it used to follow from high <= maxQ and high > low), so --azim-min-q 50 with no maximum is accepted and ResolveHighQ then calls std::clamp with its lower bound above its upper bound, which is undefined. Co-Authored-By: Claude Opus 5 (1M context) --- common/AzimuthalIntegrationSettings.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/AzimuthalIntegrationSettings.cpp b/common/AzimuthalIntegrationSettings.cpp index de5504c9..54f23bf5 100644 --- a/common/AzimuthalIntegrationSettings.cpp +++ b/common/AzimuthalIntegrationSettings.cpp @@ -23,6 +23,10 @@ AzimuthalIntegrationSettings &AzimuthalIntegrationSettings::SolidAngleCorrection AzimuthalIntegrationSettings &AzimuthalIntegrationSettings::QRange_recipA(float low, std::optional high) { check_finite("Low Q for azimuthal integration", low); check_min("Low Q for azimuthal integration", low, minQ_recipA); + // The low limit has to leave room for at least one bin below maxQ. This used to follow from the + // high limit being mandatory (high <= maxQ and high > low); once "unset" became legal, ResolveHighQ + // was left computing std::clamp(q, low + spacing, maxQ) with the lower bound above the upper one. + check_max("Low Q for azimuthal integration", low, maxQ_recipA - q_spacing); if (high.has_value()) { check_finite("High Q for azimuthal integration", *high); check_max("High Q for azimuthal integration", *high, maxQ_recipA);