summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2012-04-15 17:43:45 +0000
committerCarl Hetherington <carl@carlh.net>2012-04-15 17:43:45 +0000
commit2c0f704f286f05ce1505f6eb882391222e770331 (patch)
treea738a923ba24910efb198c96df033f43a99620f0 /libs
parent1f33d60aff8af3db5e4e115b3ecb0aceff5f417e (diff)
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
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/tempo.cc16
1 files changed, 12 insertions, 4 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 ());
-
- /* Distance to the end in frames */
- framecnt_t const distance_to_end = end - pos;
+ framepos_t end;
+ /* Distance to `end' in frames */
+ framepos_t distance_to_end;
+
+ 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);