summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-01-03 09:47:09 +0000
committerJim Meyering <jim@meyering.net>2001-01-03 09:47:09 +0000
commitb042ca3c0f6dbd42e9fc9c898d44aa878810b06d (patch)
tree46fd0547730954be7fc655b8d07ab8bbeafcf6d5 /src
parent5d3b5e175ae89d9a3fa604dbfef864195f897a7a (diff)
downloadcoreutils-b042ca3c0f6dbd42e9fc9c898d44aa878810b06d.tar.xz
(long_time_expected_width, print_long_format): Fix
bug: the initial byte passed to strftime wasn't initialized to a nonzero value after the buffer was reallocated.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/ls.c b/src/ls.c
index 3713e3c13..93215e36e 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -2362,9 +2362,14 @@ long_time_expected_width (void)
size_t bufsize = sizeof initbuf;
size_t len;
- *buf = '\1';
- while (! (len = strftime (buf, bufsize, fmt, tm)) && *buf)
- buf = alloca (bufsize *= 2);
+ for (;;)
+ {
+ *buf = '\1';
+ len = strftime (buf, bufsize, fmt, tm);
+ if (len || ! *buf)
+ break;
+ buf = alloca (bufsize *= 2);
+ }
width = mbsnwidth (buf, len, 0);
if (width < 0)
@@ -2491,12 +2496,15 @@ print_long_format (const struct fileinfo *f)
int recent = six_months_ago <= when && when <= now;
char const *fmt = long_time_format[recent];
- *p = '\1';
- while (! (s = strftime (p, buf + bufsize - p - 1, fmt, when_local))
- && *p)
+ for (;;)
{
- char *newbuf = (char *) alloca (bufsize *= 2);
+ char *newbuf;
+ *p = '\1';
+ s = strftime (p, buf + bufsize - p - 1, fmt, when_local);
+ if (s || ! *p)
+ break;
+ newbuf = alloca (bufsize *= 2);
memcpy (newbuf, buf, p - buf);
p = newbuf + (p - buf);
buf = newbuf;