cl-xmpp、cl-sasl编码函数string-to-utf8的一个bug

在使用cl-xmpp登录gtalk过程中,发现库的一个小问题,这个问题在cl-sasl上面的一个编码转换函数,发现传入为nil的情况下,挂了,原因很明白,nil的时候就不能继续操作了,然后修改后的代码是这样:

;;seems have some bug in sasl-string-to-utf8 if the string is nil it run error ? rewrite it will be ok :).

(in-package :sasl)
(defun string-to-utf8-lisp (string)
"Convert STRING to UTF-8.  Return a vector of unsigned-bytes."
(if (eq string nil)
(setf string ""))
(let (result)
    (loop for c across string
    do
    (let ((code (char-code c)))
    (cond
    ((<= code #x7f)
    ;; 0xxxxxxx
    (push code result))

   ((<= code #x7ff)
    ;; 110xxxxx 10xxxxxx
    (push (logior #b11000000
      (ash (logand #b11111000000 code)
     -6))
    result)
    (push (logior #b10000000
      (logand #b111111 code))
    result))

   ((<= code #xffff)
    ;; 1110xxxx 10xxxxxx 10xxxxxx
    (push (logior #b11100000
      (ash (logand #b1111000000000000 code)
     -12))
    result)
    (push (logior #b10000000
      (ash (logand #b111111000000 code)
     -6))
    result)
    (push (logior #b10000000
      (logand #b111111 code))
    result))

   ((<= code #x10ffff)
    ;; 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    (push (logior #b11110000
      (ash (logand #b111000000000000000000 code)
     -18))
    result)
    (push (logior #b10000000
      (ash (logand #b111111000000000000 code)
     -12))
    result)
    (push (logior #b10000000
      (ash (logand #b111111000000 code)
     -6))
    result)
    (push (logior #b10000000
      (logand #b111111 code))
    result))

   (t
    (error "Unknown code point: ~a" code)))))
(let ((length (length result)))
  (make-array length
  :element-type '(unsigned-byte 8)
  :initial-contents (nreverse result)))))

修改好后跑起来就没问题了。