gnucash master: Defer calling the bl::format::str()'s c-str() until point of use.

John Ralls jralls at code.gnucash.org
Thu Dec 22 14:00:54 EST 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/80c015d6 (commit)
	from  https://github.com/Gnucash/gnucash/commit/0421ff83 (commit)



commit 80c015d6d623b0a1bbaafed0279dfff61054b5d5
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Dec 22 10:58:39 2022 -0800

    Defer calling the bl::format::str()'s c-str() until point of use.
    
    Otherwise the string is a temporary that gets destructed at the end
    of the statement and passing the char* to gnc_update_splash_screen
    is a use-after-free.
    
    Fixes macOS CI.

diff --git a/gnucash/gnucash.cpp b/gnucash/gnucash.cpp
index 76a26a52f..541fca5e7 100644
--- a/gnucash/gnucash.cpp
+++ b/gnucash/gnucash.cpp
@@ -176,11 +176,11 @@ scm_run_gnucash (void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **
         const auto checking = _("Checking Finance::Quote...");
         gnc_update_splash_screen (checking, GNC_SPLASH_PERCENTAGE_UNKNOWN);
         GncQuotes quotes;
-        auto found = (bl::format (std::string{_("Found Finance::Quote version {1}.")}) % quotes.version()).str().c_str();
+        auto found = (bl::format (std::string{_("Found Finance::Quote version {1}.")}) % quotes.version()).str();
         auto quote_sources = quotes.sources_as_glist();
         gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
         g_list_free (quote_sources);
-        gnc_update_splash_screen (found, GNC_SPLASH_PERCENTAGE_UNKNOWN);
+        gnc_update_splash_screen (found.c_str(), GNC_SPLASH_PERCENTAGE_UNKNOWN);
     }
     catch (const GncQuoteException& err)
     {



Summary of changes:
 gnucash/gnucash.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)



More information about the gnucash-changes mailing list