From 4dbdaf7fe97deb9425e6b31cd221c2e4c1a25cb9 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 21 Jun 2022 11:39:03 -0600 Subject: [PATCH] fix possible negative return from TempoPoint::quarters_at_superclock() --- libs/temporal/tempo.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/temporal/tempo.cc b/libs/temporal/tempo.cc index 507e84e593..ec6b3eca2a 100644 --- a/libs/temporal/tempo.cc +++ b/libs/temporal/tempo.cc @@ -587,7 +587,18 @@ TempoPoint::quarters_at_superclock (superclock_t sc) const DEBUG_TRACE (DEBUG::TemporalMap, string_compose ("%8 => \nsc %1 delta %9 = %2 secs rem = %3 rem snotes %4 sbeats = %5 => %6 : %7\n", sc, whole_seconds, remainder, supernotes, superbeats, b , t, *this, sc_delta)); - return _quarters + Beats (b, t); + const Beats ret = _quarters + Beats (b, t); + + /* positive superclock can never generate negative beats unless + * it is too large. If that happens, handle it the same way as + * the opening special case in this method. + */ + + if (sc >= 0 && ret < Beats()) { + return std::numeric_limits::max(); + } + + return ret; } const double b = (exp (_omega * (sc - _sclock)) - 1) / (superclocks_per_quarter_note() * _omega);