From 01e74f496236908d66b43b386ac3f976c569b12f Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 25 Oct 2022 17:52:36 +0200 Subject: [PATCH 1/3] qt: Fix warning Push before popping or the compiler complains --- qt/pool.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qt/pool.cpp b/qt/pool.cpp index fe052788..c5adda9a 100644 --- a/qt/pool.cpp +++ b/qt/pool.cpp @@ -230,6 +230,7 @@ bool Pool::addComponent(const AppStream::Component& cpt) uint Pool::cacheFlags() const { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" return as_pool_get_cache_flags(d->pool); #pragma GCC diagnostic pop @@ -237,6 +238,7 @@ uint Pool::cacheFlags() const void Pool::setCacheFlags(uint flags) { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" as_pool_set_cache_flags(d->pool, (AsCacheFlags) flags); @@ -245,6 +247,7 @@ void Pool::setCacheFlags(uint flags) void Pool::clearMetadataLocations() { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" as_pool_clear_metadata_locations(d->pool); #pragma GCC diagnostic pop @@ -252,6 +255,7 @@ void Pool::clearMetadataLocations() void Pool::addMetadataLocation(const QString& directory) { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" as_pool_add_metadata_location (d->pool, qPrintable(directory)); #pragma GCC diagnostic pop @@ -259,6 +263,7 @@ void Pool::addMetadataLocation(const QString& directory) QString AppStream::Pool::cacheLocation() const { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" return QString::fromUtf8(as_pool_get_cache_location(d->pool)); #pragma GCC diagnostic pop @@ -266,6 +271,7 @@ QString AppStream::Pool::cacheLocation() const void Pool::setCacheLocation(const QString &location) { +#pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" as_pool_set_cache_location(d->pool, qPrintable(location)); #pragma GCC diagnostic pop From 0efd3a352f49c01788ea6f7d78ed3f1e0ff08dd2 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 25 Oct 2022 17:54:31 +0200 Subject: [PATCH 2/3] qt: Fix stringListToCharArray Make sure the list is NULL-terminated as expected --- qt/chelpers.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qt/chelpers.h b/qt/chelpers.h index 0c90486f..5c4eb3da 100644 --- a/qt/chelpers.h +++ b/qt/chelpers.h @@ -77,12 +77,13 @@ inline QStringList valueWrap(GList *list) inline char ** stringListToCharArray(const QStringList& list) { - char **array = (char**) g_malloc(sizeof(char*) * list.size()); + char **array = (char**) g_malloc(sizeof(char*) * list.size() + 1); for (int i = 0; i < list.size(); ++i) { const QByteArray string = list[i].toLocal8Bit(); array[i] = (char*) g_malloc(sizeof(char) * (string.size() + 1)); strcpy(array[i], string.constData()); } + array[list.size()] = nullptr; return array; } From 60e7a199833c47727cbb93e771190a71a466739c Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 25 Oct 2022 17:54:03 +0200 Subject: [PATCH 3/3] qt: Fix Pool::componentsByCategories Makes sure we don't use a string that is out of scope, keeps the UTF-8 formatted array until affer as_pool_get_components_by_categories is called. --- qt/pool.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qt/pool.cpp b/qt/pool.cpp index c5adda9a..f9d82b01 100644 --- a/qt/pool.cpp +++ b/qt/pool.cpp @@ -24,6 +24,7 @@ #include #include #include +#include "chelpers.h" Q_LOGGING_CATEGORY(APPSTREAMQT_POOL, "appstreamqt.pool") @@ -147,9 +148,15 @@ QList Pool::componentsByCategories(const QStringList& cate QList res; g_autofree gchar **cats_strv = NULL; - cats_strv = g_new0(gchar *, categories.size() + 1); - for (int i = 0; i < categories.size(); ++i) - cats_strv[i] = (gchar*) qPrintable(categories.at(i)); + QVector utf8Categories; + utf8Categories.reserve(categories.size()); + for (const QString &category : categories) { + utf8Categories += category.toUtf8(); + } + + cats_strv = g_new0(gchar *, utf8Categories.size() + 1); + for (int i = 0; i < utf8Categories.size(); ++i) + cats_strv[i] = (gchar*) utf8Categories[i].constData(); return cptArrayToQList(as_pool_get_components_by_categories (d->pool, cats_strv)); }