From 2c0f704f286f05ce1505f6eb882391222e770331 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 15 Apr 2012 17:43:45 +0000 Subject: [PATCH] Fix overflow when computing framewalk_to_beats with -ve pos; fixes #4694. git-svn-id: svn://localhost/ardour2/branches/3.0@11982 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/tempo.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/ardour/tempo.cc b/libs/ardour/tempo.cc index ef74c09c27..c8fd5f14cb 100644 --- a/libs/ardour/tempo.cc +++ b/libs/ardour/tempo.cc @@ -2177,10 +2177,18 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const while (distance) { /* End of this section */ - framepos_t const end = ((next_tempo == metrics.end()) ? max_framepos : (*next_tempo)->frame ()); + framepos_t end; + /* Distance to `end' in frames */ + framepos_t distance_to_end; - /* Distance to the end in frames */ - framecnt_t const distance_to_end = end - pos; + if (next_tempo == metrics.end ()) { + /* We can't do (end - pos) if end is max_framepos, as it will overflow if pos is -ve */ + end = max_framepos; + distance_to_end = max_framepos; + } else { + end = (*next_tempo)->frame (); + distance_to_end = end - pos; + } /* Amount to subtract this time */ double const sub = min (distance, distance_to_end);