Skip to content

Commit 3b16b91

Browse files
committed
Fallback when an error occurs with UTF-8 encoding
1 parent 8067007 commit 3b16b91

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/async-process.lisp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,17 @@
9595

9696
(defun pointer-to-string (pointer)
9797
(unless (cffi:null-pointer-p pointer)
98-
(let ((bytes (loop :for i :from 0
99-
:for code := (cffi:mem-aref pointer :unsigned-char i)
100-
:until (zerop code)
101-
:collect code)))
102-
(babel:octets-to-string
103-
(make-array (length bytes)
104-
:element-type '(unsigned-byte 8)
105-
:initial-contents bytes)))))
98+
(let* ((bytes (loop :for i :from 0
99+
:for code := (cffi:mem-aref pointer :unsigned-char i)
100+
:until (zerop code)
101+
:collect code))
102+
(octets (make-array (length bytes)
103+
:element-type '(unsigned-byte 8)
104+
:initial-contents bytes)))
105+
(handler-case (babel:octets-to-string octets)
106+
(error ()
107+
;; Fallback when an error occurs with UTF-8 encoding
108+
(map 'string #'code-char octets))))))
106109

107110
(defun process-receive-output (process)
108111
(let ((cffi:*default-foreign-encoding* (process-encode process)))

0 commit comments

Comments
 (0)