This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #15346] Allow leading and trailing spaces in getdate
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Mon, 8 Apr 2013 15:37:42 +0200
- Subject: Re: [PATCH][BZ #15346] Allow leading and trailing spaces in getdate
- References: <20130408125233 dot GS32556 at spoyarek dot pnq dot redhat dot com> <20130408132913 dot GA9017 at domone dot kolej dot mff dot cuni dot cz>
On Mon, Apr 08, 2013 at 03:29:13PM +0200, OndÅej BÃlka wrote:
> Could be simplified, see below.
>
> On Mon, Apr 08, 2013 at 06:22:33PM +0530, Siddhesh Poyarekar wrote:
> > Hi,
> >
> > + size_t string_len = strlen (string);
> > + int i = 0;
> > + bool free_instr = false;
> > +
> > + /* Skip leading spaces. */
> > + while (string[i] && isspace (string[i]))
> > + i++;
> > +
> /* Skip trailing spaces. */
> while (string_len > 0 && isspace (string[string_len]))
should be
while (string_len > 0 && isspace (string[string_len - 1]))
> string_len--;
>
>
> > + char *instr;
> > + if (__libc_use_alloca (string_len))
> > + {
> > + instr = alloca (string_len - i + 1);
> > + memcpy (instr, string + i, string_len - i + 1);
>
> instr[string_len - i] = '\0'
>
> > + }
> > + else
> > + {
> > + instr = __strdup (string + i);
> > + if (instr == NULL)
> > + {
> > + fclose (fp);
> > + return 6;
> > + }
> > + free_instr = true;
> > + }
> > +
> > +
> > line = NULL;
> > len = 0;
> > do
> > @@ -153,12 +190,15 @@ __getdate_r (const char *string, struct tm *tp)
> > tp->tm_isdst = -1;
> > tp->tm_gmtoff = 0;
> > tp->tm_zone = NULL;
> > - result = strptime (string, line, tp);
> > + result = strptime (instr, line, tp);
> > if (result && *result == '\0')
> > break;
> > }
> > while (!feof_unlocked (fp));
> >
> > + if (free_instr)
> > + free (instr);
> > +
> > /* Free the buffer. */
> > free (line);
> >
> > diff --git a/time/tst-getdate.c b/time/tst-getdate.c
> > index 7604e83..dc8ecf4 100644
> > --- a/time/tst-getdate.c
> > +++ b/time/tst-getdate.c
> > @@ -31,6 +31,10 @@ static const struct
> > } tests [] =
> > {
> > {"21:01:10 1999-1-31", "Universal", 0, {10, 1, 21, 31, 0, 99, 0, 0, 0}},
> > + {"21:01:10 1999-1-31", "Universal", 0, {10, 1, 21, 31, 0, 99, 0, 0, 0}},
> > + {" 21:01:10 1999-1-31", "Universal", 0, {10, 1, 21, 31, 0, 99, 0, 0, 0}},
> > + {"21:01:10 1999-1-31 ", "Universal", 0, {10, 1, 21, 31, 0, 99, 0, 0, 0}},
> > + {" 21:01:10 1999-1-31 ", "Universal", 0, {10, 1, 21, 31, 0, 99, 0, 0, 0}},
> > {"21:01:10 1999-2-28", "Universal", 0, {10, 1, 21, 28, 1, 99, 0, 0, 0}},
> > {"16:30:46 2000-2-29", "Universal", 0, {46, 30,16, 29, 1, 100, 0, 0, 0}},
> > {"01-08-2000 05:06:07", "Europe/Berlin", 0, {7, 6, 5, 1, 7, 100, 0, 0, 0}}
>
> --
>
> appears to be a Slow/Narrow SCSI-0 Interface problem
--
The electrician didn't know what the yellow cable was so he yanked the ethernet out.