]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: better nstrftime failure check
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 1 Nov 2025 23:39:07 +0000 (17:39 -0600)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 2 Nov 2025 00:00:32 +0000 (18:00 -0600)
* src/ls.c (print_long_format): Streamline the checking
for failure of nstrftime.

src/ls.c

index 5183a414e308586d075da5664ac9a4b3e54dec79..7144d0d9accf8e57a3863553b7aa717d51436ee8 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -4422,8 +4422,7 @@ print_long_format (const struct fileinfo *f)
       p[-1] = ' ';
     }
 
-  s = 0;
-  *p = '\1';
+  s = -1;
 
   if (f->stat_ok && btime_ok
       && localtime_rz (localtz, &when_timespec.tv_sec, &when_local))
@@ -4451,11 +4450,9 @@ print_long_format (const struct fileinfo *f)
          whole number of seconds.  */
       s = align_nstrftime (p, TIME_STAMP_LEN_MAXIMUM + 1, recent,
                            &when_local, localtz, when_timespec.tv_nsec);
-      if (s < 0)
-        s = 0;
     }
 
-  if (s || !*p)
+  if (0 <= s)
     {
       p += s;
       *p++ = ' ';