From 1184d2085a2a4d4cb7cae4caf0a21eb495206722 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 13 Oct 2012 09:06:18 -0700 Subject: [PATCH] Don't crash on --print-variables when there are no variables Apparently g_hash_table_foreach doesn't check for NULL input, so make sure we don't call it to print the variables if the variable list is empty. Freedesktop #54721 --- check/Makefile.am | 3 ++- check/check-print-options | 5 ++++- check/no-variables.pc | 3 +++ main.c | 7 ++++--- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 check/no-variables.pc diff --git a/check/Makefile.am b/check/Makefile.am index 64a6151..7330e52 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -49,4 +49,5 @@ EXTRA_DIST = \ non-l-required.pc \ circular-1.pc \ circular-2.pc \ - circular-3.pc + circular-3.pc \ + no-variables.pc diff --git a/check/check-print-options b/check/check-print-options index ab02b05..f9ce636 100755 --- a/check/check-print-options +++ b/check/check-print-options @@ -11,7 +11,10 @@ run_test --version RESULT=1.0.0 run_test --modversion simple -# --print-variables +# --print-variables, make sure having no variables doesn't crash +RESULT="" +run_test --print-variables no-variables + RESULT="exec_prefix prefix libdir diff --git a/check/no-variables.pc b/check/no-variables.pc new file mode 100644 index 0000000..20bcaa6 --- /dev/null +++ b/check/no-variables.pc @@ -0,0 +1,3 @@ +Name: No Variables +Description: Test package having no variables to check --print-variables +Version: 4.2 diff --git a/main.c b/main.c index 385e43d..2aea422 100644 --- a/main.c +++ b/main.c @@ -580,9 +580,10 @@ main (int argc, char **argv) while (tmp != NULL) { Package *pkg = tmp->data; - g_hash_table_foreach(pkg->vars, - &print_hashtable_key, - NULL); + if (pkg->vars != NULL) + g_hash_table_foreach(pkg->vars, + &print_hashtable_key, + NULL); tmp = g_slist_next (tmp); if (tmp) printf ("\n"); }