[svn:parrot] r47896 - branches/hash_allocator/src

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Jun 28 11:10:18 UTC 2010


Author: chromatic
Date: Mon Jun 28 11:10:17 2010
New Revision: 47896
URL: https://trac.parrot.org/parrot/changeset/47896

Log:
[src] Improved hash_value_to_number();

As value can be NULL, it's important not to crash by trying to dereference NULL
as a STRING or a PMC.  They numify to 0.0 now; we can throw an exception as
necessary.

Modified:
   branches/hash_allocator/src/hash.c

Modified: branches/hash_allocator/src/hash.c
==============================================================================
--- branches/hash_allocator/src/hash.c	Mon Jun 28 08:44:59 2010	(r47895)
+++ branches/hash_allocator/src/hash.c	Mon Jun 28 11:10:17 2010	(r47896)
@@ -2013,12 +2013,16 @@
 {
     ASSERT_ARGS(hash_value_to_number)
     FLOATVAL ret;
+
+    if (!value)
+        return 0.0;
+
     switch (hash->entry_type) {
       case enum_type_INTVAL:
         {
             /* Pacify compiler about casting */
             const INTVAL tmp = (INTVAL)value;
-            ret = tmp;
+            ret = (FLOATVAL)tmp;
         }
         break;
       case enum_type_STRING:
@@ -2031,6 +2035,7 @@
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED,
                     "Hash: unsupported entry_type");
     }
+
     return ret;
 }
 


More information about the parrot-commits mailing list