guile-devel
[Top][All Lists]
Advanced

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

SCM_NUM2ULONG doesn't detect negative non-INUMs


From: Martin Baulig
Subject: SCM_NUM2ULONG doesn't detect negative non-INUMs
Date: 01 Sep 2001 14:53:54 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Hi,

calling SCM_NUM2ULONG() on a negative non-immediate number doesn't
raise an exception if the number is larger than -ULONG_MAX - and it
returns the positive value of that number.

Example:

        -1                              => exception
        -2147483648     (INT_MIN)       => +214748364
        -4294967295     (-ULONG_MAX)    => +4294967295
        -4294967296                     => exception
        -100000000000000                => exception

I guess this is a bug, isn't it ?

>From looking at the code, there's

====[num2integral.i.c - line 50]=====
#ifndef UNSIGNED
      if (SCM_BIGSIGN (num))
        {
          res = -res;
          if (res <= 0)
            return res;
          else
            scm_out_of_range (s_caller, num);
        }
      else
        {
          if (res >= 0)
            return res;
          else
            scm_out_of_range (s_caller, num);
        }
#endif
====

So for unsigned numbers, we don't even check whether the number is
negative and thus don't catch it.

Here's a patch:

Attachment: diff
Description: Text document

-- 
Martin Baulig
address@hidden (private)
address@hidden (work)

reply via email to

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