From 6207fce91a0933e852ec76fc31ca81ec00ffa04b Mon Sep 17 00:00:00 2001
From: Wilfried Goesgens <dothebart@citadel.org>
Date: Thu, 5 Jun 2014 20:04:13 +0200
Subject: [PATCH 11/22] Configparser: when we alocate an empty list, we also
 need to reset the counter; else we will trip over this later. This fixes
 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=750440

---
 src/configfile.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/configfile.c b/src/configfile.c
index 0b7786f..983d995 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -414,6 +414,12 @@ static int cf_ci_replace_child (oconfig_item_t *dst, oconfig_item_t *src,
 
 	/* Resize the memory containing the children to be big enough to hold
 	 * all children. */
+	if (dst->children_num + src->children_num - 1 == 0)
+	{
+		dst->children_num = 0;
+		return (0);
+	}
+
 	temp = (oconfig_item_t *) realloc (dst->children,
 			sizeof (oconfig_item_t)
 			* (dst->children_num + src->children_num - 1));
@@ -514,7 +520,8 @@ static int cf_include_all (oconfig_item_t *root, int depth)
 			continue;
 
 		/* Now replace the i'th child in `root' with `new'. */
-		cf_ci_replace_child (root, new, i);
+		if (cf_ci_replace_child (root, new, i) < 0)
+			return (-1);
 
 		/* ... and go back to the new i'th child. */
 		--i;
-- 
1.9.3

