comparison layer/Colour3DPlotLayer.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 db0759e4c6c3
children a1226b3b7925
comparison
equal deleted inserted replaced
863:7c75fae51409 864:3ca3b8fbbcee
1329 cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << endl; 1329 cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << endl;
1330 #endif 1330 #endif
1331 1331
1332 QPoint illuminatePos; 1332 QPoint illuminatePos;
1333 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); 1333 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
1334 char labelbuf[10]; 1334
1335 const int buflen = 40;
1336 char labelbuf[buflen];
1335 1337
1336 for (int sx = sx0; sx <= sx1; ++sx) { 1338 for (int sx = sx0; sx <= sx1; ++sx) {
1337 1339
1338 int fx = sx * modelResolution; 1340 int fx = sx * modelResolution;
1339 1341
1393 1395
1394 if (showLabel) { 1396 if (showLabel) {
1395 if (sx >= 0 && sx < m_cache->width() && 1397 if (sx >= 0 && sx < m_cache->width() &&
1396 sy >= 0 && sy < m_cache->height()) { 1398 sy >= 0 && sy < m_cache->height()) {
1397 float value = m_model->getValueAt(sx, sy); 1399 float value = m_model->getValueAt(sx, sy);
1398 sprintf(labelbuf, "%06f", value); 1400 snprintf(labelbuf, buflen, "%06f", value);
1399 QString text(labelbuf); 1401 QString text(labelbuf);
1400 paint.setPen(v->getBackground()); 1402 paint.setPen(v->getBackground());
1401 paint.drawText(rx0 + 2, 1403 paint.drawText(rx0 + 2,
1402 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), 1404 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
1403 text); 1405 text);