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
This commit is contained in:
Dan Nicholson 2012-10-13 09:06:18 -07:00
parent a14d489fbc
commit 1184d2085a
4 changed files with 13 additions and 5 deletions

View file

@ -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

View file

@ -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

3
check/no-variables.pc Normal file
View file

@ -0,0 +1,3 @@
Name: No Variables
Description: Test package having no variables to check --print-variables
Version: 4.2

7
main.c
View file

@ -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");
}