[svn:parrot] r45978 - trunk/src/string

NotFound at svn.parrot.org NotFound at svn.parrot.org
Sat Apr 24 08:26:20 UTC 2010


Author: NotFound
Date: Sat Apr 24 08:26:20 2010
New Revision: 45978
URL: https://trac.parrot.org/parrot/changeset/45978

Log:
fix Parrot_str_to_int to deal with PARROT_INTVAL_MIN

Modified:
   trunk/src/string/api.c

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Sat Apr 24 06:25:08 2010	(r45977)
+++ trunk/src/string/api.c	Sat Apr 24 08:26:20 2010	(r45978)
@@ -1843,10 +1843,10 @@
     if (STRING_IS_NULL(s))
         return 0;
     {
-        const INTVAL        max_safe  = PARROT_INTVAL_MAX / 10;
-        const INTVAL        last_dig  = PARROT_INTVAL_MAX % 10;
+        const UINTVAL       max_safe  = -(UINTVAL)PARROT_INTVAL_MIN / 10;
+        const UINTVAL       last_dig  = (-(UINTVAL)PARROT_INTVAL_MIN) % 10;
         int                 sign      = 1;
-        INTVAL              i         = 0;
+        UINTVAL             i         = 0;
         String_iter         iter;
         UINTVAL             offs;
         number_parse_state  state = parse_start;
@@ -1862,7 +1862,7 @@
             switch (state) {
               case parse_start:
                 if (isdigit((unsigned char)c)) {
-                    const INTVAL nextval = c - '0';
+                    const UINTVAL nextval = c - '0';
                     if (i < max_safe || (i == max_safe && nextval <= last_dig))
                         i = i * 10 + nextval;
                     else
@@ -1886,7 +1886,7 @@
 
               case parse_before_dot:
                 if (isdigit((unsigned char)c)) {
-                    const INTVAL nextval = c - '0';
+                    const UINTVAL nextval = c - '0';
                     if (i < max_safe || (i == max_safe && nextval <= last_dig))
                         i = i * 10 + nextval;
                     else
@@ -1904,9 +1904,11 @@
             }
         }
 
-        i *= sign;
-
-        return i;
+        if (sign == 1 && i > (UINTVAL)PARROT_INTVAL_MAX)
+            Parrot_ex_throw_from_c_args(interp, NULL,
+                    EXCEPTION_ERR_OVERFLOW,
+                    "Integer value of String '%S' too big", s);
+        return sign == -1 ? -i : i;
     }
 }
 


More information about the parrot-commits mailing list