[recipes] Fix a crash with "Buy ingredients"



commit 28753f61c46037fcac55868409bfe4eaa1d396de
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Feb 15 13:52:28 2017 -0500

    Fix a crash with "Buy ingredients"

 src/gr-recipe-store.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-recipe-store.c b/src/gr-recipe-store.c
index f04aa3d..f30e80c 100644
--- a/src/gr-recipe-store.c
+++ b/src/gr-recipe-store.c
@@ -1057,7 +1057,7 @@ gr_recipe_store_init (GrRecipeStore *self)
         if (load_favorites (self, dir))
                 save_favorites (self);
         if (load_shopping (self, dir))
-                save_favorites (self);
+                save_shopping (self);
         if (load_cooked (self, dir))
                 save_cooked (self);
         if (load_chefs (self, dir, FALSE))
@@ -1520,6 +1520,13 @@ gr_recipe_store_last_favorite_change (GrRecipeStore *self)
         return self->favorite_change;
 }
 
+static void
+ensure_shopping (GrRecipeStore *self)
+{
+        if (!self->shopping)
+                self->shopping = g_new0 (char *, 1);
+}
+
 void
 gr_recipe_store_add_to_shopping (GrRecipeStore *self,
                                  GrRecipe      *recipe,
@@ -1531,6 +1538,8 @@ gr_recipe_store_add_to_shopping (GrRecipeStore *self,
         int i;
         const char *id;
 
+        ensure_shopping (self);
+
         id = gr_recipe_get_id (recipe);
 
         for (i = 0; self->shopping[i]; i++) {
@@ -1573,6 +1582,8 @@ gr_recipe_store_remove_from_shopping (GrRecipeStore *self,
         int i, j;
         const char *id;
 
+        ensure_shopping (self);
+
         id = gr_recipe_get_id (recipe);
 
         for (i = 0; self->shopping[i]; i++) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]