summaryrefslogtreecommitdiff
path: root/src/date.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-08-18 19:50:35 +0000
committerJim Meyering <jim@meyering.net>1997-08-18 19:50:35 +0000
commitb5ef7a4be75e46cd44eb2f3cfa2512a84026ce98 (patch)
tree2b48bbb1a6e5b608dd91e16fb9119d1b6c41c90e /src/date.c
parent41347fc40e8258539e69e2604abbbd88a875e22e (diff)
downloadcoreutils-b5ef7a4be75e46cd44eb2f3cfa2512a84026ce98.tar.xz
(show_date): Don't hang if strftime produces an empty string.
Diffstat (limited to 'src/date.c')
-rw-r--r--src/date.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/date.c b/src/date.c
index 36bc01feb..591264e5c 100644
--- a/src/date.c
+++ b/src/date.c
@@ -399,8 +399,14 @@ show_date (const char *format, time_t when)
{
out_length += 200;
out = (char *) xrealloc (out, out_length);
+
+ /* Mark the first byte of the buffer so we can detect the case
+ of strftime producing an empty string. Otherwise, this loop
+ would not terminate when date was invoked like this
+ `LANG=de date +%p' on a system with good language support. */
+ out[0] = '\1';
}
- while (strftime (out, out_length, format, tm) == 0);
+ while (strftime (out, out_length, format, tm) == 0 && out[0] != '\0');
printf ("%s\n", out);
free (out);