(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)