This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
glibc strftime.c bug: assumes subformats yield nonempty buffers
- To: libc-alpha@cygnus.com
- Subject: glibc strftime.c bug: assumes subformats yield nonempty buffers
- From: Paul Eggert <eggert@twinsun.com>
- Date: Thu, 24 Sep 1998 13:54:27 -0700 (PDT)
- References: <199809241751.LAA02366@wijiji.santafe.edu>
While fixing the other bugs, I noticed by code inspection that glibc
strftime's subformat code assumes that subformats yield nonempty
strings. This isn't true e.g. if the subformat is "%p" and %p yields
the empty string in this locale. Here is a patch.
1998-09-24 Paul Eggert <eggert@twinsun.com>
* strftime.c (my_strftime): When asking for the length of the
subformatted buffer, do not limit the length to look for;
otherwise, we have no reliable way to distinguish between the
empty buffer and an error.
--- strftime.c 1998/09/24 20:46:02 2.0.96.4
+++ strftime.c 1998/09/24 20:51:19 2.0.96.5
@@ -717,7 +717,5 @@ my_strftime (s, maxsize, format, tp)
{
char *old_start = p;
- size_t len = my_strftime (NULL, maxsize - i, subfmt, tp);
- if (len == 0 && *subfmt)
- return 0;
+ size_t len = my_strftime (NULL, (size_t) -1, subfmt, tp);
add (len, my_strftime (p, maxsize - i, subfmt, tp));