Fix a crash when downloading binary - clic - Clic is an command line interactive client for gopher written in Common LISP
 (HTM) git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d07922a2554fc78ba5efe7e9818e4cb7fbfd6938
 (DIR) parent 02fda5b5bc6564db46dde5a1a2e2f5e71a75321d
 (HTM) Author: Solene Rapenne <solene@perso.pw>
       Date:   Tue,  2 Jan 2018 10:22:35 +0100
       
       Fix a crash when downloading binary
       
       Diffstat:
         M clic.lisp                           |      24 +++++++++++++++---------
       
       1 file changed, 15 insertions(+), 9 deletions(-)
       ---
 (DIR) diff --git a/clic.lisp b/clic.lisp
       @@ -274,15 +274,19 @@
                  ;; not terminal = write to stdio
                  (if (ttyp)
                      ;; save into a file in /tmp
       -              (let ((filename (subseq uri (1+ (position #\/ uri :from-end t)))))
       -                (with-open-file (output (concatenate 'string "/tmp/" filename)
       +              (let* ((filename (subseq uri (1+ (position #\/ uri :from-end t))))
       +                     (path (concatenate 'string "/tmp/" filename)))
       +                (with-open-file (output path
                                                :element-type '(unsigned-byte 8)
                                                :direction :output :if-exists :supersede)
                          (let ((buf (make-array 4096 :element-type '(unsigned-byte 8))))
                            (loop for pos = (read-sequence buf stream)
                               while (plusp pos)
                               do
       -                         (write-sequence buf output :end pos)))))
       +                         (format t ".")
       +                         (force-output)
       +                         (write-sequence buf output :end pos)))
       +                  (format t "~%File downloaded into ~a (~a bytes)~%" path (file-length output))))
        
                      ;; write to the standard output
                      (let ((buf (make-array 4096 :element-type '(unsigned-byte 8))))
       @@ -474,9 +478,10 @@
                                       :output :interactive))
                   ;; display last menu
                   (pop *history*)
       -           (setf *buffer* (copy-array *previous-buffer*))
       -           (setf *links* (make-hash-table))
       -           (display-buffer "1")))
       +           (when *previous-buffer*
       +             (setf *buffer* (copy-array *previous-buffer*))
       +             (setf *links* (make-hash-table))
       +             (display-buffer "1"))))
        
                ;; image
                ((or
       @@ -492,9 +497,10 @@
                                                                       (location-uri location)
                                                                       :from-end t)))))))
                 (pop *history*)
       -         (setf *buffer* (copy-array *previous-buffer*))
       -         (setf *links* (make-hash-table))
       -         (display-buffer "1"))
       +         (when *previous-buffer*
       +           (setf *buffer* (copy-array *previous-buffer*))
       +           (setf *links* (make-hash-table))
       +           (display-buffer "1")))
        
        
                ;;;; output is a menu ?