You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(defun byte-array-to-hex-string (vector &key (start 0) end (element-type 'base-char))
"Return a string containing the hexadecimal representation of the
subsequence of VECTOR between START and END. ELEMENT-TYPE controls
the element-type of the returned string."
(declare (type (vector (unsigned-byte 8)) vector)
(type fixnum start)
(type (or null fixnum) end)
(optimize (speed 3) (safety 1)))
(let* ((end (or end (length vector)))
(length (- end start))
(hexdigits #.(coerce "0123456789abcdef" 'simple-base-string)))
(loop with string = (ecase element-type
;; so that the compiler optimization can jump in
(base-char (make-string (* length 2)
:element-type 'base-char))
(character (make-string (* length 2)
:element-type 'character)))
for i from start below end
for j from 0 below (* length 2) by 2
do (let ((byte (aref vector i)))
#+ecl
(declare (optimize (safety 1)))
#-ecl
(declare (optimize (safety 0)))
(setf (aref string j)
(aref hexdigits (ldb (byte 4 4) byte))
(aref string (1+ j))
(aref hexdigits (ldb (byte 4 0) byte))))
finally (return string))))
Notes:
I am using Ubuntu 22.04 on x64.
Ironclad tests pass.
The text was updated successfully, but these errors were encountered:
cdmojoli
changed the title
Under ECL 24.5.10 byte-array-to-hex-string miscompiles due to (safety 0)
Under ECL 24.5.10 byte-array-to-hex-string (v0.59) miscompiles due to (safety 0)
Oct 6, 2024
(In the exhibit below, scroll to the right to see the mismatch.)
Simply changing safety to 1 solves this:
Notes:
The text was updated successfully, but these errors were encountered: