Subject: Avoid integer wrap around when zooming in.
Bug: http://sourceforge.net/support/tracker.php?aid=1720945
Origin: http://sourceforge.net/support/tracker.php?aid=1720945
Applied-Upstream: no
---
 plotmm/doubleintmap.h |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

--- plotmm.orig/plotmm/doubleintmap.h
+++ plotmm/plotmm/doubleintmap.h
@@ -11,6 +11,7 @@
 #define PLOTMM_DBLINTMAP_H
 
 #include <plotmm/supplemental.h>
+#include <limits>
 
 namespace PlotMM {
 
@@ -143,10 +144,10 @@ namespace PlotMM {
      */
     inline int DoubleIntMap::transform(double x) const
     {
-	if (d_log)
-	    return d_y1 + ROUND((log(x) - d_x1) * d_cnv);
-	else
-	    return d_y1 + ROUND((x - d_x1) * d_cnv);
+	double y(((d_log ? log(x) : x)  - d_x1) * d_cnv);
+	y = std::min(std::numeric_limits<short>::max() - (double)d_y1,
+		     std::max(std::numeric_limits<short>::min() - (double)d_y1, y));
+	return d_y1 + ROUND(y);
     }
 
 }
