GNU bug report logs - #26013
(srfi srfi-37) chokes on empty string parameter

Previous Next

Package: guile;

Reported by: Thomas Danckaert <post <at> thomasdanckaert.be>

Date: Tue, 7 Mar 2017 15:36:01 UTC

Severity: normal

Done: Andy Wingo <wingo <at> igalia.com>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 26013 <at> debbugs.gnu.org (full text, mbox):

From: Thomas Danckaert <post <at> thomasdanckaert.be>
To: wingo <at> igalia.com
Cc: ludo <at> gnu.org, 26013 <at> debbugs.gnu.org
Subject: Re: bug#26013: (srfi srfi-37) chokes on empty string parameter
Date: Wed, 19 Apr 2017 18:32:29 +0200 (CEST)
[Message part 1 (text/plain, inline)]
From: Andy Wingo <wingo <at> igalia.com>
Subject: Re: bug#26013: (srfi srfi-37) chokes on empty string 
parameter
Date: Wed, 19 Apr 2017 17:13:25 +0200

> On Tue 07 Mar 2017 16:34, Thomas Danckaert 
> <post <at> thomasdanckaert.be> writes:
>
>> It looks like Guile's srfi-37 implementation doesn't process empty
>> string arguments correctly.
>> [...]
>> In srfi/srfi-37.scm:
>>  220: 1 [next-arg]
>> In unknown file:
>>    ?: 0 [string-ref "" 0]
>>
>> ERROR: In procedure string-ref:
>> ERROR: Value out of range: 0
>
> Sounds like the right diagnosis to me.  Want to submit a patch? :)

Well, let me try :)

I don't fully understand the code in srfi-37.scm, but I think the fix 
can be as simple as the attached patch (i.e. first check if the 
argument is empty, otherwise check if it starts with \#-).

I have tried to follow the existing indentation convention, as far as 
I understand it (a mix of tabs and spaces).

Thomas
[0001-SRFI-37-Account-for-zero-length-arguments.patch (text/x-patch, inline)]
From bd0bd95e3786211effe728bae61ef5b02f6cc5f6 Mon Sep 17 00:00:00 2001
From: Thomas Danckaert <thomas.danckaert <at> gmail.com>
Date: Wed, 19 Apr 2017 18:14:38 +0200
Subject: [PATCH] SRFI-37: Account for zero-length arguments.

* module/srfi/srfi-37.scm (args-fold): When checking if an argument is
an option (starts with #\-), first check if the length is non-zero.
---
 module/srfi/srfi-37.scm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/module/srfi/srfi-37.scm b/module/srfi/srfi-37.scm
index 3f654af2c..c34b0d083 100644
--- a/module/srfi/srfi-37.scm
+++ b/module/srfi/srfi-37.scm
@@ -217,7 +217,8 @@ program-arguments in ARGS, as decided by the OPTIONS'
       (if (null? args)
 	  (apply values seeds)
 	  (let ((arg (car args)))
-	    (cond ((or (not (char=? #\- (string-ref arg 0)))
+	    (cond ((or (string-null? arg)
+		       (not (char=? #\- (string-ref arg 0)))
 		       (= 1 (string-length arg))) ;"-"
 		   (mutate-seeds! operand-proc arg)
 		   (set! args (cdr args)))
-- 
2.12.2


This bug report was last modified 8 years and 126 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.