diff layer/LinearColourScale.cpp @ 864:3ca3b8fbbcee

Correct some really stupid fixed-length string stuff, including a genuine stack overflow that causes a crash on OS/X for certain colour 3d plot data.
author Chris Cannam
date Mon, 29 Sep 2014 13:27:13 +0100
parents 1d526ba11a24
children b66fb15de477
line wrap: on
line diff
--- a/layer/LinearColourScale.cpp	Fri Sep 12 11:50:26 2014 +0100
+++ b/layer/LinearColourScale.cpp	Mon Sep 29 13:27:13 2014 +0100
@@ -43,8 +43,9 @@
 
     float val = min;
     float inc = (max - val) / n;
-
-    char buffer[40];
+    
+    const int buflen = 40;
+    char buffer[buflen];
 
     int boxx = 5, boxy = 5;
     if (layer->getScaleUnits() != "") {
@@ -84,7 +85,7 @@
 	ty = y - paint.fontMetrics().height() +
 	    paint.fontMetrics().ascent() + 2;
 
-	sprintf(buffer, "%.*f", dp, val);
+	snprintf(buffer, buflen, "%.*f", dp, val);
 	QString label = QString(buffer);
 
 	paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);