Skip to content

Commit bf954d1

Browse files
authored
fixes the sign handling in the atoi stub (#1240)
1 parent 2b911c3 commit bf954d1

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

plugins/primus_lisp/lisp/ascii.lisp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
(= s 32)))
1111

1212
(defun ascii-sign (s)
13-
"(ascii-sign S) is 1 if S is + and -1 otherwise"
14-
(if (= s ?+) 1 -1))
13+
"(ascii-sign S) is 1 if S is +, -1 if it -, or 0 otherwise"
14+
(case s
15+
?- -1
16+
?+ 1
17+
0))
1518

1619
(defun ascii-is-digit (s)
1720
"(ascii-is-digit s) is true if S is an ascii representation of decimal digit"

plugins/primus_lisp/lisp/atoi.lisp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
(skip-all atoi-prefix s)
1515
(let ((v 0)
1616
(sign (ascii-sign (memory-read s))))
17+
(if (= sign 0)
18+
(set sign 1)
19+
(incr s))
1720
(while (ascii-is-digit (memory-read s))
1821
(set v (+ (* v 10) (atoi-read-digit s)))
1922
(incr s))

0 commit comments

Comments
 (0)