changeset 986:e8e6c4e7437b

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 f073d924a7c3
children a51781b11dd4
files base/Debug.cpp data/fft/FFTDataServer.cpp
diffstat 2 files changed, 11 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/base/Debug.cpp	Tue Sep 16 10:29:19 2014 +0100
+++ b/base/Debug.cpp	Mon Sep 29 13:27:13 2014 +0100
@@ -43,8 +43,9 @@
     QDir logdir(QString("%1/%2").arg(pfx).arg("log"));
 
     if (!prefix) {
-        prefix = new char[20];
-        sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid());
+        prefix = strdup(QString("[%1]")
+                        .arg(QCoreApplication::applicationPid())
+                        .toLatin1().data());
         //!!! what to do if mkpath fails?
 	if (!logdir.exists()) logdir.mkpath(logdir.path());
     }
--- a/data/fft/FFTDataServer.cpp	Tue Sep 16 10:29:19 2014 +0100
+++ b/data/fft/FFTDataServer.cpp	Mon Sep 29 13:27:13 2014 +0100
@@ -1428,18 +1428,14 @@
                                     int fftSize,
                                     bool polar)
 {
-    char buffer[200];
-
-    sprintf(buffer, "%u-%u-%u-%u-%u-%u%s",
-            (unsigned int)XmlExportable::getObjectExportId(model),
-            (unsigned int)(channel + 1),
-            (unsigned int)windowType,
-            (unsigned int)windowSize,
-            (unsigned int)windowIncrement,
-            (unsigned int)fftSize,
-            polar ? "-p" : "-r");
-
-    return buffer;
+    return QString("%1-%2-%3-%4-%5-%6%7")
+        .arg(XmlExportable::getObjectExportId(model))
+        .arg(channel + 1)
+        .arg((int)windowType)
+        .arg(windowSize)
+        .arg(windowIncrement)
+        .arg(fftSize)
+        .arg(polar ? "-p" : "-r");
 }
 
 void