[PATCH] Handle empty valued fields with newer external popt

Dan Nicholson dbn.lists at gmail.com
Mon May 24 20:32:00 PDT 2010


The bundled popt handled the case of Cflags or Libs with no value, but
newer popt linked through --with-installed-popt chokes parsing it into
a vector. This is arguably a popt bug in poptParseArgvString, but I
guess they expect you not to ask it to split an empty string.
---
 parse.c |   52 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/parse.c b/parse.c
index c383c57..37dfd20 100644
--- a/parse.c
+++ b/parse.c
@@ -741,7 +741,7 @@ parse_libs (Package *pkg, const char *str, const char *path)
   
   char *trimmed;
   char **argv = NULL;
-  int argc;
+  int argc = 0;
   int result;
   
   if (pkg->libs_num > 0)
@@ -753,15 +753,19 @@ parse_libs (Package *pkg, const char *str, const char *path)
   
   trimmed = trim_and_sub (pkg, str, path);
 
-  result = poptParseArgvString (trimmed, &argc, &argv);
-
-  if (result < 0)
+  if (trimmed && *trimmed)
     {
-      verbose_error ("Couldn't parse Libs field into an argument vector: %s\n",
-               poptStrerror (result));
+      result = poptParseArgvString (trimmed, &argc, &argv);
 
-      exit (1);
+      if (result < 0)
+        {
+          verbose_error ("Couldn't parse Libs field into an argument vector: %s\n",
+                         poptStrerror (result));
+
+          exit (1);
+        }
     }
+
   _do_parse_libs(pkg, argc, argv);
 
   g_free (trimmed);
@@ -786,7 +790,7 @@ parse_libs_private (Package *pkg, const char *str, const char *path)
   
   char *trimmed;
   char **argv = NULL;
-  int argc;
+  int argc = 0;
   int result;
   
   if (pkg->libs_private_num > 0)
@@ -798,14 +802,17 @@ parse_libs_private (Package *pkg, const char *str, const char *path)
   
   trimmed = trim_and_sub (pkg, str, path);
 
-  result = poptParseArgvString (trimmed, &argc, &argv);
-
-  if (result < 0)
+  if (trimmed && *trimmed)
     {
-      verbose_error ("Couldn't parse Libs.private field into an argument vector: %s\n",
-               poptStrerror (result));
+      result = poptParseArgvString (trimmed, &argc, &argv);
 
-      exit (1);
+      if (result < 0)
+        {
+          verbose_error ("Couldn't parse Libs.private field into an argument vector: %s\n",
+                         poptStrerror (result));
+
+          exit (1);
+        }
     }
 
   _do_parse_libs(pkg, argc, argv);
@@ -823,7 +830,7 @@ parse_cflags (Package *pkg, const char *str, const char *path)
   
   char *trimmed;
   char **argv = NULL;
-  int argc;
+  int argc = 0;
   int result;
   int i;
   
@@ -836,14 +843,17 @@ parse_cflags (Package *pkg, const char *str, const char *path)
   
   trimmed = trim_and_sub (pkg, str, path);
 
-  result = poptParseArgvString (trimmed, &argc, &argv);
-
-  if (result < 0)
+  if (trimmed && *trimmed)
     {
-      verbose_error ("Couldn't parse Cflags field into an argument vector: %s\n",
-                     poptStrerror (result));
+      result = poptParseArgvString (trimmed, &argc, &argv);
 
-      exit (1);
+      if (result < 0)
+        {
+          verbose_error ("Couldn't parse Cflags field into an argument vector: %s\n",
+                         poptStrerror (result));
+
+          exit (1);
+        }
     }
 
   i = 0;
-- 
1.6.6.1


More information about the pkg-config mailing list