bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#11887: string->number edge cases


From: Mark H Weaver
Subject: bug#11887: string->number edge cases
Date: Tue, 05 Mar 2013 14:04:55 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Andy Wingo <address@hidden> writes:

> On Mon 09 Jul 2012 14:29, Ian Price <address@hidden> writes:
>
>> If the number contains a division by zero, we get a numerical overflow
>> error.
>>
>> scheme@(guile−user)> (string->number "3/0")
>> ERROR: In procedure string−>number:
>> ERROR: Throw to key `numerical−overflow' with args `("make−ratio" "Numerical 
>> overflow" #f #f)'.
>
> This is also an error.  We should plumb through some extra arg to
> mem2ureal, I guess, to check for a zero denominator.

FYI, I produced a simple patch a while back to fix this (see below), but
it had an interesting side effect: it caused the reader to read things
like "3/0" and "4+3/0i" as symbols.  More generally, anything for which
'scm_string_to_number' returns false is treated as a symbol by 'read'.

I'm not sure how I feel about this.  What do you think?

     Mark


diff --git a/libguile/numbers.c b/libguile/numbers.c
index 66c95db..9013f0c 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -5809,7 +5809,7 @@ mem2ureal (SCM mem, unsigned int *p_idx,
             return SCM_BOOL_F;
 
          divisor = mem2uinteger (mem, &idx, radix, &implicit_x);
-         if (scm_is_false (divisor))
+         if (scm_is_false (divisor) || scm_is_eq (divisor, SCM_INUM0))
            return SCM_BOOL_F;
 
          /* both are int/big here, I assume */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]