Mercurial > hg > svgui
changeset 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 | 7c75fae51409 |
children | de9472751d31 |
files | layer/Colour3DPlotLayer.cpp layer/LinearColourScale.cpp layer/LinearNumericalScale.cpp layer/LogColourScale.cpp layer/LogNumericalScale.cpp |
diffstat | 5 files changed, 17 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Fri Sep 12 11:50:26 2014 +0100 +++ b/layer/Colour3DPlotLayer.cpp Mon Sep 29 13:27:13 2014 +0100 @@ -1331,7 +1331,9 @@ QPoint illuminatePos; bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); - char labelbuf[10]; + + const int buflen = 40; + char labelbuf[buflen]; for (int sx = sx0; sx <= sx1; ++sx) { @@ -1395,7 +1397,7 @@ if (sx >= 0 && sx < m_cache->width() && sy >= 0 && sy < m_cache->height()) { float value = m_model->getValueAt(sx, sy); - sprintf(labelbuf, "%06f", value); + snprintf(labelbuf, buflen, "%06f", value); QString text(labelbuf); paint.setPen(v->getBackground()); paint.drawText(rx0 + 2,
--- 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);
--- a/layer/LinearNumericalScale.cpp Fri Sep 12 11:50:26 2014 +0100 +++ b/layer/LinearNumericalScale.cpp Mon Sep 29 13:27:13 2014 +0100 @@ -42,7 +42,8 @@ float val = minf; float inc = (maxf - val) / n; - char buffer[40]; + const int buflen = 40; + char buffer[buflen]; int w = getWidth(v, paint) + x0; @@ -86,7 +87,7 @@ continue; } - sprintf(buffer, "%.*f", dp, dispval); + snprintf(buffer, buflen, "%.*f", dp, dispval); QString label = QString(buffer);
--- a/layer/LogColourScale.cpp Fri Sep 12 11:50:26 2014 +0100 +++ b/layer/LogColourScale.cpp Mon Sep 29 13:27:13 2014 +0100 @@ -46,7 +46,8 @@ float val = minlog; float inc = (maxlog - val) / n; - char buffer[40]; + const int buflen = 40; + char buffer[buflen]; int boxx = 5, boxy = 5; if (layer->getScaleUnits() != "") { @@ -85,7 +86,7 @@ int digits = trunc(log10f(dv)); int sf = dp + (digits > 0 ? digits : 0); if (sf < 2) sf = 2; - sprintf(buffer, "%.*g", sf, dv); + snprintf(buffer, buflen, "%.*g", sf, dv); QString label = QString(buffer);
--- a/layer/LogNumericalScale.cpp Fri Sep 12 11:50:26 2014 +0100 +++ b/layer/LogNumericalScale.cpp Mon Sep 29 13:27:13 2014 +0100 @@ -55,7 +55,8 @@ cerr << "min = " << minlog << ", max = " << maxlog << ", inc = " << inc << ", minDispInc = " << minDispInc << endl; #endif - char buffer[40]; + const int buflen = 40; + char buffer[buflen]; float round = 1.f; int dp = 0; @@ -104,7 +105,7 @@ #ifdef DEBUG_TIME_VALUE_LAYER cerr << "sf = " << sf << endl; #endif - sprintf(buffer, "%.*g", sf, dispval); + snprintf(buffer, buflen, "%.*g", sf, dispval); QString label = QString(buffer);