This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3][BZ #15346] Allow leading and trailing spaces in getdate
- From: Roland McGrath <roland at hack dot frob dot com>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: OndÅej BÃlka <neleai at seznam dot cz>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Tue, 9 Apr 2013 09:39:19 -0700 (PDT)
- Subject: Re: [PATCH v3][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> <20130408141120 dot GA15689 at spoyarek dot pnq dot redhat dot com> <20130408201256 dot E3C762C09F at topped-with-meat dot com> <20130409043315 dot GC15689 at spoyarek dot pnq dot redhat dot com>
> @@ -135,6 +137,37 @@ __getdate_r (const char *string, struct tm *tp)
> /* No threads reading this stream. */
> __fsetlocking (fp, FSETLOCKING_BYCALLER);
>
> + size_t inlen = strlen (string);
> + int i = 0;
> + bool free_instr = false;
> +
> + /* Skip leading whitespace. */
> + while (isspace (string[i]))
> + i++;
> +
> + /* Skip trailing whitespace. */
> + while (inlen > i && isspace (string[inlen - 1]))
> + inlen--;
> +
> + inlen -= i;
Let's avoid the copy when it's unnecessary. So, start incrementing STRING
itself for the leading whitespace (and don't do strlen til after that).
Then only do the copy if the trailing whitespace check found anything to trim.
Thanks,
Roland