[geocode-glib] lib: Use a dynamic array instead of a static one



commit bee16294df1f70ce044701680919a92db68a2e88
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Dec 3 07:48:48 2012 +0100

    lib: Use a dynamic array instead of a static one

 geocode-glib/geocode-forward.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index 7695ace..2a3d8cb 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -633,7 +633,6 @@ make_location_list_from_tree (GNode   *node,
 	GNode *child;
 	GeocodeLocation *loc;
 	char *description, *name;
-	char *rev_s_array[N_ATTRS + 2]; /* name + 7 attrs + NULL */
 	int counter = 0;
 	gboolean add_attribute = FALSE;
 
@@ -641,6 +640,10 @@ make_location_list_from_tree (GNode   *node,
 		return;
 
 	if (G_NODE_IS_LEAF (node)) {
+		GPtrArray *rev_s_array;
+
+		rev_s_array = g_ptr_array_new ();
+
 		/* If leaf node, then add all the attributes in the s_array
 		 * and set it to the description of the loc object */
 		loc = (GeocodeLocation *) node->data;
@@ -649,14 +652,15 @@ make_location_list_from_tree (GNode   *node,
 
 		/* To print the attributes in a meaningful manner
 		 * reverse the s_array */
-		rev_s_array[0] = name;
+		g_ptr_array_add (rev_s_array, name);
 		counter = 1;
 		while (counter <= i) {
-			rev_s_array[counter] = s_array[i - counter];
+			g_ptr_array_add (rev_s_array, s_array[i - counter]);
 			counter++;
 		}
-		rev_s_array[counter] = NULL;
-		description = g_strjoinv (", ", rev_s_array);
+		g_ptr_array_add (rev_s_array, NULL);
+		description = g_strjoinv (", ", (char **) rev_s_array->pdata);
+		g_ptr_array_unref (rev_s_array);
 
 		loc->description = description;
 		g_free (name);



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