Qt: avoid NULL to terminate a g_build_filename in ExportObjectModel

While documentation for g_build_filename suggests the use of NULL as
terminator, the C++ standard permits NULL to be defined as integer 0.
This potentially has a different size than a void pointer and can cause
crashes if this is the case. Instead of using (void*)0 as terminator,
let's just rewrite this piece to avoid the problem in its entirely.

Fixes "missing sentinel" warning in GCC with musl due to NULL being 0L.

Change-Id: I6a7911887eaeeaa56fdb03d14ee8b70a42c8a05b
Reviewed-on: https://code.wireshark.org/review/34107
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Peter Wu 2019-07-28 21:01:00 +01:00
parent 04c12dd67b
commit 3951759e83
1 changed files with 7 additions and 8 deletions

View File

@ -14,6 +14,8 @@
#include <ui/qt/utils/variant_pointer.h>
#include <ui/export_object_ui.h>
#include <QDir>
extern "C" {
static void
@ -157,6 +159,7 @@ void ExportObjectModel::saveAllEntries(QString path)
if (path.isEmpty())
return;
QDir save_dir(path);
export_object_entry_t *entry;
for (QList<QVariant>::iterator it = objects_.begin(); it != objects_.end(); ++it)
@ -166,12 +169,11 @@ void ExportObjectModel::saveAllEntries(QString path)
continue;
int count = 0;
gchar *save_as_fullpath = NULL;
QString filename;
do {
GString *safe_filename;
g_free(save_as_fullpath);
if (entry->filename)
safe_filename = eo_massage_str(entry->filename,
EXPORT_OBJECT_MAXFILELEN, count);
@ -185,13 +187,10 @@ void ExportObjectModel::saveAllEntries(QString path)
safe_filename = eo_massage_str(generic_name,
EXPORT_OBJECT_MAXFILELEN, count);
}
save_as_fullpath = g_build_filename(path.toUtf8().constData(),
safe_filename->str, NULL);
filename = QString::fromUtf8(safe_filename->str);
g_string_free(safe_filename, TRUE);
} while (g_file_test(save_as_fullpath, G_FILE_TEST_EXISTS) && ++count < 1000);
eo_save_entry(save_as_fullpath, entry);
g_free(save_as_fullpath);
save_as_fullpath = NULL;
} while (save_dir.exists(filename) && ++count < 1000);
eo_save_entry(save_dir.filePath(filename).toUtf8().constData(), entry);
}
}