comparison layer/LogColourScale.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
44 int n = 10; 44 int n = 10;
45 45
46 float val = minlog; 46 float val = minlog;
47 float inc = (maxlog - val) / n; 47 float inc = (maxlog - val) / n;
48 48
49 char buffer[40]; 49 const int buflen = 40;
50 char buffer[buflen];
50 51
51 int boxx = 5, boxy = 5; 52 int boxx = 5, boxy = 5;
52 if (layer->getScaleUnits() != "") { 53 if (layer->getScaleUnits() != "") {
53 boxy += paint.fontMetrics().height(); 54 boxy += paint.fontMetrics().height();
54 } 55 }
83 84
84 double dv = LogRange::unmap(val); 85 double dv = LogRange::unmap(val);
85 int digits = trunc(log10f(dv)); 86 int digits = trunc(log10f(dv));
86 int sf = dp + (digits > 0 ? digits : 0); 87 int sf = dp + (digits > 0 ? digits : 0);
87 if (sf < 2) sf = 2; 88 if (sf < 2) sf = 2;
88 sprintf(buffer, "%.*g", sf, dv); 89 snprintf(buffer, buflen, "%.*g", sf, dv);
89 90
90 QString label = QString(buffer); 91 QString label = QString(buffer);
91 92
92 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y); 93 paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
93 paint.drawText(tx, ty, label); 94 paint.drawText(tx, ty, label);