changeset 24435:3b5ee0390edd

(ls-lisp-insert-directory): Protect the sum total of the file sizes from overflowing. (ls-lisp-format): If file size is a float, use %8.0f to print it.
author Eli Zaretskii <eliz@gnu.org>
date Thu, 04 Mar 1999 11:30:27 +0000
parents 3c42b33fb636
children e5af0407bcd6
files lisp/ls-lisp.el
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ls-lisp.el	Thu Mar 04 09:16:12 1999 +0000
+++ b/lisp/ls-lisp.el	Thu Mar 04 11:30:27 1999 +0000
@@ -138,6 +138,7 @@
 		 file-alist 
 		 (now (current-time))
 		 ;; do all bindings here for speed
+		 file-size
 		 fil attr)
 	    (cond ((memq ?A switches)
 		   (setq file-list
@@ -168,10 +169,19 @@
 	      (setq elt (car file-alist)
 		    file-alist (cdr file-alist)
 		    short (car elt)
-		    attr (cdr elt))
+		    attr (cdr elt)
+		    file-size (nth 7 attr))
 	      (and attr
-		   (setq sum (+ sum (nth 7 attr)))
-		   (insert (ls-lisp-format short attr switches now))))
+		   (setq sum
+			 ;; Even if neither SUM nor file's size
+			 ;; overflow, their sum could.
+			 (if (or (< sum (- 134217727 file-size))
+				 (floatp sum)
+				 (floatp file-size))
+			     (+ sum file-size)
+			   (+ (float sum) file-size)))
+		   (insert (ls-lisp-format short attr file-size switches now))
+		   ))
 	    ;; Fill in total size of all files:
 	    (save-excursion
 	      (search-backward "total \007")
@@ -182,7 +192,8 @@
 	;; file-attributes will not recognize a symlink to a directory
 	;; must make it a relative filename as ls does:
 	(setq file (file-name-nondirectory file))
-	(insert (ls-lisp-format file (file-attributes file) switches
+	(insert (ls-lisp-format file (file-attributes file)
+				(nth 7 (file-attributes file)) switches
 				(current-time)))))))
 
 (defun ls-lisp-delete-matching (regexp list)
@@ -240,19 +251,21 @@
 	     (< lo0 lo1)))))
 
 
-(defun ls-lisp-format (file-name file-attr switches now)
+(defun ls-lisp-format (file-name file-attr file-size switches now)
   (let ((file-type (nth 0 file-attr)))
     (concat (if (memq ?i switches)	; inode number
 		(format "%6d " (nth 10 file-attr)))
 	    ;; nil is treated like "" in concat
 	    (if (memq ?s switches)	; size in K
-		(format "%4d " (fceiling (/ (nth 7 file-attr) 1024.0))))
+		(format "%4d " (fceiling (/ file-size 1024.0))))
 	    (nth 8 file-attr)		; permission bits
 	    ;; numeric uid/gid are more confusing than helpful
 	    ;; Emacs should be able to make strings of them.
 	    ;; user-login-name and user-full-name could take an
 	    ;; optional arg.
-	    (format " %3d %-8s %-8s %8d "
+	    (format (if (floatp file-size)
+ 			" %3d %-8s %-8s %8.0f "
+ 		      " %3d %-8s %-8s %8d ")
 		    (nth 1 file-attr)	; no. of links
 		    (if (= (user-uid) (nth 2 file-attr))
 			(user-login-name)
@@ -260,7 +273,7 @@
 		    (if (eq system-type 'ms-dos)
 			"root"		; everything is root on MSDOS.
 		      (int-to-string (nth 3 file-attr)))	; gid
-		    (nth 7 file-attr)	; size in bytes
+		    file-size
 		    )
 	    (ls-lisp-format-time file-attr switches now)
 	    " "