Skip to content

Commit

Permalink
Fallback when an error occurs with UTF-8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
cxxxr committed Oct 27, 2024
1 parent 8067007 commit 3b16b91
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/async-process.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@

(defun pointer-to-string (pointer)
(unless (cffi:null-pointer-p pointer)
(let ((bytes (loop :for i :from 0
:for code := (cffi:mem-aref pointer :unsigned-char i)
:until (zerop code)
:collect code)))
(babel:octets-to-string
(make-array (length bytes)
:element-type '(unsigned-byte 8)
:initial-contents bytes)))))
(let* ((bytes (loop :for i :from 0
:for code := (cffi:mem-aref pointer :unsigned-char i)
:until (zerop code)
:collect code))
(octets (make-array (length bytes)
:element-type '(unsigned-byte 8)
:initial-contents bytes)))
(handler-case (babel:octets-to-string octets)
(error ()
;; Fallback when an error occurs with UTF-8 encoding
(map 'string #'code-char octets))))))

(defun process-receive-output (process)
(let ((cffi:*default-foreign-encoding* (process-encode process)))
Expand Down

0 comments on commit 3b16b91

Please sign in to comment.