Ah, of course a 0-byte integer has value 0

This commit is contained in:
Tony Garnock-Jones 2020-12-30 17:39:17 +01:00
parent 85fe7b3b07
commit 77fd8e86bf
1 changed files with 4 additions and 4 deletions

View File

@ -99,10 +99,10 @@
(define (next-varint) (eof-guard (read-varint in-port)))
(define (next-integer n)
(when (zero? n) (return (on-fail "Zero-length integer not permitted")))
(define acc0 (next-byte))
(define acc (if (< acc0 128) acc0 (- acc0 256)))
(for/fold [(acc acc)] [(n (in-range (- n 1)))] (+ (* acc 256) (next-byte))))
(cond [(zero? n) 0]
[else (define acc0 (next-byte))
(define acc (if (< acc0 128) acc0 (- acc0 256)))
(for/fold [(acc acc)] [(n (in-range (- n 1)))] (+ (* acc 256) (next-byte)))]))
(define (next-items)
(define pos0 (pos))