diff options
author | Richard Hughes <richard@hughsie.com> | 2008-08-05 12:25:27 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2008-08-05 12:25:27 +0100 |
commit | 16f2c597aa03d1405c04b14595690f9717a801c8 (patch) | |
tree | 11c0e7bbe1a45a020b005a198ba1b3f4590747e3 /src/dkp-history.c | |
parent | 38f86d7dae9f190f6e33c1940452a880bf96e396 (diff) |
don't segfault when a history file is present but empty
Diffstat (limited to 'src/dkp-history.c')
-rw-r--r-- | src/dkp-history.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/dkp-history.c b/src/dkp-history.c index 8e54851..15ef90c 100644 --- a/src/dkp-history.c +++ b/src/dkp-history.c @@ -322,9 +322,15 @@ dkp_history_load_data_array (const gchar *filename, GPtrArray *array) /* split by line ending */ parts = g_strsplit (data, "\n", 0); - length = g_strv_length (parts) - 1; + length = g_strv_length (parts); + if (length == 0) { + dkp_debug ("no data in %s", filename); + goto out; + } + + /* add valid entries */ dkp_debug ("loading %i items of data from %s", length, filename); - for (i=0; i<length; i++) { + for (i=0; i<length-1; i++) { obj = dkp_history_obj_from_string (parts[i]); if (obj != NULL) g_ptr_array_add (array, obj); |