comparison 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
comparison
equal deleted inserted replaced
863:7c75fae51409 864:3ca3b8fbbcee
41 41
42 int n = 10; 42 int n = 10;
43 43
44 float val = min; 44 float val = min;
45 float inc = (max - val) / n; 45 float inc = (max - val) / n;
46 46
47 char buffer[40]; 47 const int buflen = 40;
48 char buffer[buflen];
48 49
49 int boxx = 5, boxy = 5; 50 int boxx = 5, boxy = 5;
50 if (layer->getScaleUnits() != "") { 51 if (layer->getScaleUnits() != "") {
51 boxy += paint.fontMetrics().height(); 52 boxy += paint.fontMetrics().height();
52 } 53 }
82 y = boxy + int(boxh - ((val - min) * boxh) / (max - min)); 83 y = boxy + int(boxh - ((val - min) * boxh) / (max - min));
83 84
84 ty = y - paint.fontMetrics().height() + 85 ty = y - paint.fontMetrics().height() +
85 paint.fontMetrics().ascent() + 2; 86 paint.fontMetrics().ascent() + 2;
86 87
87 sprintf(buffer, "%.*f", dp, val); 88 snprintf(buffer, buflen, "%.*f", dp, val);
88 QString label = QString(buffer); 89 QString label = QString(buffer);
89 90
90 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y); 91 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
91 paint.drawText(tx, ty, label); 92 paint.drawText(tx, ty, label);
92 93