Fix overflow when computing framewalk_to_beats with -ve pos; fixes #4694.
authorCarl Hetherington <carl@carlh.net>
Sun, 15 Apr 2012 17:43:45 +0000 (17:43 +0000)
committerCarl Hetherington <carl@carlh.net>
Sun, 15 Apr 2012 17:43:45 +0000 (17:43 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11982 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/tempo.cc

index ef74c09c2783c0c12786ac383d85e34dccb478b5..c8fd5f14cb8a990b251743aa2fb5bb211ec03041 100644 (file)
@@ -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);