From 711e650bab69fb2b24bf0ae7527e99e59f05cc49 Mon Sep 17 00:00:00 2001 From: takayuki Date: Sat, 10 Nov 2012 11:52:28 +0900 Subject: [PATCH] fix (pack "w" 0) --- cl-pack.lisp | 1 + tests.lisp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cl-pack.lisp b/cl-pack.lisp index 450d7b0..e17d1d7 100644 --- a/cl-pack.lisp +++ b/cl-pack.lisp @@ -152,6 +152,7 @@ "function to encode a BER number into a binary byte string" (let ((num_bytes (ceiling (/ (log (1+ number) 2) 7))) (n number)) + (if (eql 0 n) (incf num_bytes)) (coerce (loop for i from (1- num_bytes) downto 0 collect (code-char (+ (if (> i 0) 128 diff --git a/tests.lisp b/tests.lisp index d7c0878..6dfd2b2 100644 --- a/tests.lisp +++ b/tests.lisp @@ -104,6 +104,7 @@ (string= (pack "E" 25) (concatenate 'string (gen-null-string 6) "9@")) (string= (pack "x") (string #\null)) (string= (pack "w" 193) (coerce `(,(code-char 129) #\A) 'string)) + (string= (pack "w" 0) (coerce `(,(code-char 0)) 'string)) )) @@ -154,6 +155,7 @@ (= (unpack "G" (concatenate 'string "@9" (gen-null-string 6))) 25) (= (unpack "E" (concatenate 'string (gen-null-string 6) "9@")) 25) (= (unpack "w" (coerce `(,(code-char 129) #\A) 'string)) 193) + (= (unpack "w" (coerce `(,(code-char 0)) 'string)) 0) )) (deftest unpack-combinations ()