diff --git a/src/strings.lisp b/src/strings.lisp index d61f43870a1f9a7d5898f514182d18e5b52a7eb1..34f483de9ba1bc8bac47770f162c8063ec17518f 100644 --- a/src/strings.lisp +++ b/src/strings.lisp @@ -187,14 +187,14 @@ The string must be freed with FOREIGN-STRING-FREE." (declare (type simple-string string)) (let* ((mapping (lookup-mapping *foreign-string-mappings* encoding)) (count (funcall (octet-counter mapping) string start end 0)) - (length (if null-terminated-p - (+ count (null-terminator-len encoding)) - count)) + (nul-length (if null-terminated-p + (null-terminator-len encoding) + 0)) + (length (+ count nul-length)) (ptr (foreign-alloc :char :count length))) (funcall (encoder mapping) string start end ptr 0) - (when null-terminated-p - (dotimes (i (null-terminator-len encoding)) - (setf (mem-ref ptr :char (+ count i)) 0))) + (dotimes (i nul-length) + (setf (mem-ref ptr :char (+ count i)) 0)) (values ptr length)))) (defun foreign-string-free (ptr)