Hi all,

Yesterday's salmonella run went all wrong, and Mario figured out that this
was due to my read-line patch messing with chicken-install.

It turns out that the condition in ##sys#scan-buffer-line which reads
(and (eq? c #\return)   ; \r\n -> drop \r from string
     (fx> limit (fx+ pos 1))
     (eq? (##core#inline "C_subchar" buf (fx+ pos 1)) #\newline))
gets confused.  This is because when the user does not supply a "limit"
argument to read-line, it's set to (##sys#fudge 21), which is equal to
most-positive-fixnum.  However, later the buffer offset index is
added to it, which causes an overflow.

This patch simply subtracts the index from most-positive-fixnum to make
room for it to be added later.  It's a little messy, but I don't see a
clean way to improve it immediately.

Cheers,
Peter
-- 
http://www.more-magic.net
>From 436564139521f1f181a45ed9a276834ba49f318a Mon Sep 17 00:00:00 2001
From: Peter Bex <[email protected]>
Date: Sat, 16 Feb 2013 14:01:08 +0100
Subject: [PATCH] Get rid of overflow situation in read-line causing lines to
 be read wrong

---
 posixunix.scm | 2 +-
 tcp.scm       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/posixunix.scm b/posixunix.scm
index 251c400..650d2c3 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -1388,7 +1388,7 @@ EOF
                       (fetch))
                     (if (fx>= bufpos buflen)
                         #!eof
-                        (let ((limit (or limit (##sys#fudge 21))))
+                        (let ((limit (or limit (fx- (##sys#fudge 21) bufpos))))
                           (receive (next line)
                               (##sys#scan-buffer-line
                                buf
diff --git a/tcp.scm b/tcp.scm
index d0657a4..758c7d2 100644
--- a/tcp.scm
+++ b/tcp.scm
@@ -433,7 +433,7 @@ EOF
                   (read-input))
                 (if (fx>= bufindex buflen)
                     #!eof
-                    (let ((limit (or limit (##sys#fudge 21))))
+                    (let ((limit (or limit (fx- (##sys#fudge 21) bufindex))))
                       (receive (next line)
                           (##sys#scan-buffer-line
                            buf
-- 
1.8.0.1

_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to