On 03/03/11 14:35, Eric Blake wrote:
>> -  if (pT != NUL)
>> +  if (pz == NULL)
>> +    return BAD_TIME;
> 
> Here, you want errno to be ENOMEM, but mingw doesn't guarantee that...

Ick.

> ACK with that fixed.

ACK:

Subject: [PATCH] parse-duration: remove xalloc.h dependency

* lib/parse-duration.c (parse_period): handle NULL return from
strdup instead of calling xstrdup().
* modules/parse-duration: remove "xalloc" dependency
---
 ChangeLog              |    7 +++++++
 lib/parse-duration.c   |   16 +++++++++++-----
 modules/parse-duration |    1 -
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1b9a2f3..af2abe5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-03-03  Bruce Korb  <bk...@gnu.org>
+
+       parse-duration: remove xalloc.h dependency
+       * lib/parse-duration.c (parse_period): handle NULL return from
+       strdup instead of calling xstrdup().
+       * modules/parse-duration: remove "xalloc" dependency
+
 2011-03-03  Matthew Booth  <mbo...@redhat.com>

        bootstrap: honor m4_base when running aclocal
diff --git a/lib/parse-duration.c b/lib/parse-duration.c
index 8c28133..0a8c4ad 100644
--- a/lib/parse-duration.c
+++ b/lib/parse-duration.c
@@ -26,7 +26,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "xalloc.h"

 #ifndef NUL
 #define NUL '\0'
@@ -381,7 +380,7 @@ parse_time (cch_t * pz)
 }

 /* Returns a substring of the given string, with spaces at the beginning and at
-   the end destructively removed.  */
+   the end destructively removed, per SNOBOL.  */
 static char *
 trim (char * pz)
 {
@@ -406,13 +405,20 @@ trim (char * pz)
 static time_t
 parse_period (cch_t * in_pz)
 {
-  char * pz   = xstrdup (in_pz);
-  char * pT   = strchr (pz, 'T');
+  char * pT;
   char * ps;
+  char * pz   = strdup (in_pz);
   void * fptr = pz;
   time_t res  = 0;

-  if (pT != NUL)
+  if (pz == NULL)
+    {
+      errno = ENOMEM;
+      return BAD_TIME;
+    }
+
+  pT = strchr (pz, 'T');
+  if (pT != NULL)
     {
       *(pT++) = NUL;
       pz = trim (pz);
diff --git a/modules/parse-duration b/modules/parse-duration
index 2e8f3d1..e36c917 100644
--- a/modules/parse-duration
+++ b/modules/parse-duration
@@ -6,7 +6,6 @@ lib/parse-duration.h
 lib/parse-duration.c

 Depends-on:
-xalloc

 configure.ac:
 AC_REQUIRE([AC_C_INLINE])
-- 
1.7.1

Reply via email to