gnucash stable: [gnc-tree-container.hpp] if the GtkTreeModel is empty, init m_iter with std::nullopt

Christopher Lam clam at code.gnucash.org
Fri Aug 18 11:11:54 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/1e44d1a7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/891e3936 (commit)



commit 1e44d1a73ac3866007e6ba805a5ad7ef281cfaae
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Aug 18 23:10:15 2023 +0800

    [gnc-tree-container.hpp] if the GtkTreeModel is empty, init m_iter with std::nullopt
    
    Thus an empty container will evaluate begin()==end() as true.

diff --git a/gnucash/gnome-utils/gnc-tree-container.hpp b/gnucash/gnome-utils/gnc-tree-container.hpp
index f3afe91faa..fedd6218e9 100644
--- a/gnucash/gnome-utils/gnc-tree-container.hpp
+++ b/gnucash/gnome-utils/gnc-tree-container.hpp
@@ -79,8 +79,7 @@ public:
     GncTreeIter(GtkTreeModel* model) : m_model (model)
     {
         GtkTreeIter iter;
-        gtk_tree_model_get_iter_first(m_model, &iter);
-        m_iter = iter;
+        m_iter = gtk_tree_model_get_iter_first(m_model, &iter) ? iter : std::nullopt;
     }
 
     GncTreeIter& operator++()



Summary of changes:
 gnucash/gnome-utils/gnc-tree-container.hpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)



More information about the gnucash-changes mailing list