Get --dired offsets right when handling stat-failed entries.
authorJim Meyering <jim@meyering.net>
Tue, 25 Jul 2006 15:30:27 +0000 (15:30 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 25 Jul 2006 15:30:27 +0000 (15:30 +0000)
* src/ls.c (print_long_format): Be careful to increment P by the
appropriate amount, even when inode_number_width and nlink_width
are zero.
* tests/ls/stat-failed: Test for the above.

ChangeLog
src/ls.c
tests/ls/stat-failed

index e5cfb9c..f604a46 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2006-07-25  Jim Meyering  <jim@meyering.net>
 
+       Get --dired offsets right when handling stat-failed entries.
+       * src/ls.c (print_long_format): Be careful to increment P by the
+       appropriate amount, even when inode_number_width and nlink_width
+       are zero.
+       * tests/ls/stat-failed: Test for the above.
+
        * src/ls.c (gobble_file) [USE_ACL]: Don't use-uninitialized the
        have_acl member.  That would happen for a directory with both a
        non-stat'able entry and one with an ACL.
index 67f16bd..37e206c 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3395,7 +3395,9 @@ print_long_format (const struct fileinfo *f)
       char hbuf[INT_BUFSIZE_BOUND (uintmax_t)];
       sprintf (p, "%*s ", inode_number_width,
               f->stat_failed ? "?" : umaxtostr (f->stat.st_ino, hbuf));
-      p += inode_number_width + 1;
+      /* Increment by strlen (p) here, rather than by inode_number_width + 1.
+        The latter is wrong when inode_number_width is zero.  */
+      p += strlen (p);
     }
 
   if (print_block_size)
@@ -3421,7 +3423,10 @@ print_long_format (const struct fileinfo *f)
     sprintf (p, "%s %*s ", modebuf, nlink_width,
             f->stat_failed ? "?" : umaxtostr (f->stat.st_nlink, hbuf));
   }
-  p += sizeof modebuf - 2 + any_has_acl + 1 + nlink_width + 1;
+  /* Increment by strlen (p) here, rather than by, e.g.,
+     sizeof modebuf - 2 + any_has_acl + 1 + nlink_width + 1.
+     The latter is wrong when nlink_width is zero.  */
+  p += strlen (p);
 
   DIRED_INDENT ();
 
index a7c0066..bf86681 100755 (executable)
@@ -33,4 +33,26 @@ fail=0
 ls -Log d > out 2> err
 test $? = 1 || fail=1
 
+cat <<\EOF > exp || fail=1
+total 0
+?--------- ? ?            ? d/s
+EOF
+
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
+
+# Ensure that the offsets in --dired output are accurate.
+rm -f out exp
+ls --dired -il d > out 2> /dev/null && fail=1
+
+cat <<\EOF > exp || fail=1
+  total 0
+  ? ?--------- ? ? ? ?            ? d/s
+//DIRED// 46 49
+//DIRED-OPTIONS// --quoting-style=literal
+EOF
+
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
+
 (exit $fail); exit $fail