gnucash stable: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Fri Mar 31 14:46:23 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/fb0814ce (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6ba5bb32 (commit)
	from  https://github.com/Gnucash/gnucash/commit/17e08d0f (commit)



commit fb0814ced5eeb1618e0cb390908e815cff8c3658
Merge: 17e08d0f43 6ba5bb326a
Author: John Ralls <jralls at ceridwen.us>
Date:   Fri Mar 31 11:30:09 2023 -0700

    Merge Richard Cohen's 'fix-clang1507-build' into stable.


commit 6ba5bb326aed025e166ce782c59ea955b9d7161f
Author: Richard Cohen <richard at daijobu.co.uk>
Date:   Tue Mar 28 13:53:57 2023 +0100

    Fix dereference of expired temporaries.
    
    Reported by clang 15.0.7, which will be in Ubuntu 23.04, -Wdangling-gsl

diff --git a/libgnucash/backend/xml/test/test-file-stuff.cpp b/libgnucash/backend/xml/test/test-file-stuff.cpp
index da5f14151e..3cfd29ec06 100644
--- a/libgnucash/backend/xml/test/test-file-stuff.cpp
+++ b/libgnucash/backend/xml/test/test-file-stuff.cpp
@@ -261,13 +261,10 @@ equals_node_val_vs_kvp_frame (xmlNodePtr node, const KvpFrame* frm)
     }
     else
     {
-        auto frm1str = g_strdup (frm->to_string ().c_str ());
-        auto frm2str = g_strdup (cmpfrm->to_string ().c_str ());
+        auto frmstr = frm->to_string ();
+        auto cmpfrmstr = cmpfrm->to_string ();
 
-        printf ("%s vs %s\n", frm1str, frm2str);
-
-        g_free (frm1str);
-        g_free (frm2str);
+        printf ("%s vs %s\n", frmstr.c_str(), cmpfrmstr.c_str());
 
         delete cmpfrm;
         return FALSE;
diff --git a/libgnucash/core-utils/gnc-filepath-utils.cpp b/libgnucash/core-utils/gnc-filepath-utils.cpp
index 28f6b57acd..5de8c436d6 100644
--- a/libgnucash/core-utils/gnc-filepath-utils.cpp
+++ b/libgnucash/core-utils/gnc-filepath-utils.cpp
@@ -211,7 +211,10 @@ gchar *gnc_file_path_relative_part (const gchar *prefix, const gchar *path)
 {
     std::string p{path};
     if (p.find(prefix) == 0)
-        return g_strdup(p.substr(strlen(prefix)).c_str());
+    {
+        auto str = p.substr(strlen(prefix));
+        return g_strdup(str.c_str());
+    }
     return g_strdup(path);
 }
 
diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp
index a2bdea6319..202b5dbb01 100644
--- a/libgnucash/engine/gnc-date.cpp
+++ b/libgnucash/engine/gnc-date.cpp
@@ -1101,7 +1101,8 @@ qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
 gchar *
 gnc_date_timestamp (void)
 {
-    return g_strdup(GncDateTime::timestamp().c_str());
+    auto timestamp = GncDateTime::timestamp();
+    return g_strdup(timestamp.c_str());
 }
 
 /********************************************************************\
diff --git a/libgnucash/engine/gnc-features.cpp b/libgnucash/engine/gnc-features.cpp
index 79bfea18c8..2204f5ea34 100644
--- a/libgnucash/engine/gnc-features.cpp
+++ b/libgnucash/engine/gnc-features.cpp
@@ -65,10 +65,13 @@ header = N_("This Dataset contains features not supported "
 gchar *gnc_features_test_unknown (QofBook *book)
 {
     auto unknowns {qof_book_get_unknown_features (book, features_table)};
+    if (unknowns.empty())
+        return nullptr;
+
     auto accum = [](const auto& a, const auto& b){ return a + "\n* " + b; };
-    return unknowns.empty() ? nullptr :
-        g_strdup (std::accumulate (unknowns.begin(), unknowns.end(),
-                                   std::string (_(header)), accum).c_str());
+    auto msg {std::accumulate (unknowns.begin(), unknowns.end(),
+                                   std::string (_(header)), accum)};
+    return g_strdup (msg.c_str());
 }
 
 void gnc_features_set_used (QofBook *book, const gchar *feature)
diff --git a/libgnucash/engine/gnc-optiondb.cpp b/libgnucash/engine/gnc-optiondb.cpp
index 7ef2b10fbf..021b119968 100644
--- a/libgnucash/engine/gnc-optiondb.cpp
+++ b/libgnucash/engine/gnc-optiondb.cpp
@@ -459,7 +459,10 @@ GncOptionDB::save_to_kvp(QofBook* book, bool clear_options) const noexcept
                              * have to store. */
                             kvp = new KvpValue(option.template get_value<double>());
                         else
-                            kvp = new KvpValue{g_strdup(option.template get_value<std::string>().c_str())};
+                        {
+                            auto str{option.template get_value<std::string>()};
+                            kvp = new KvpValue{g_strdup(str.c_str())};
+                        }
                         qof_book_set_option(book, kvp, &list_head);
                     }
                 });
diff --git a/libgnucash/engine/qofinstance.cpp b/libgnucash/engine/qofinstance.cpp
index 9b931622fd..11d77e1656 100644
--- a/libgnucash/engine/qofinstance.cpp
+++ b/libgnucash/engine/qofinstance.cpp
@@ -1102,8 +1102,8 @@ qof_instance_compare_kvp (const QofInstance *a, const QofInstance *b)
 char*
 qof_instance_kvp_as_string (const QofInstance *inst)
 {
-    //The std::string is a local temporary and doesn't survive this function.
-    return g_strdup(inst->kvp_data->to_string().c_str());
+    auto str{inst->kvp_data->to_string()};
+    return g_strdup(str.c_str());
 }
 
 void



Summary of changes:
 libgnucash/backend/xml/test/test-file-stuff.cpp | 9 +++------
 libgnucash/core-utils/gnc-filepath-utils.cpp    | 5 ++++-
 libgnucash/engine/gnc-date.cpp                  | 3 ++-
 libgnucash/engine/gnc-features.cpp              | 9 ++++++---
 libgnucash/engine/gnc-optiondb.cpp              | 5 ++++-
 libgnucash/engine/qofinstance.cpp               | 4 ++--
 6 files changed, 21 insertions(+), 14 deletions(-)



More information about the gnucash-changes mailing list