Permalink
Browse files

FOREIGN-STRING-ALLOC: don't call NULL-TERMINATOR-LEN twice

  • Loading branch information...
stassats authored and sionescu committed Nov 24, 2012
1 parent dab3137 commit 32170642e829a5d6baf6323d4ef2a3b2999f7353
Showing with 6 additions and 6 deletions.
  1. +6 −6 src/strings.lisp
View
@@ -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)

0 comments on commit 3217064

Please sign in to comment.