help-smalltalk
[Top][All Lists]
Advanced

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

[Help-smalltalk] [PATCH 3/4] tweak index_oop_spec and index_oop_put_spec


From: Paolo Bonzini
Subject: [Help-smalltalk] [PATCH 3/4] tweak index_oop_spec and index_oop_put_spec index computations
Date: Mon, 7 Oct 2013 10:17:47 +0200

libgst:
2013-10-07  Paolo Bonzini  <address@hidden>

        * libgst/dict.inl: In index_oop_spec and index_oop_put_spec,
        move index decrement after the scaling by sizeof(type) and the
        overflow test.  This prepares for fixing the overflow test.
---
 libgst/ChangeLog |  6 ++++++
 libgst/dict.inl  | 20 ++++++++++----------
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libgst/ChangeLog b/libgst/ChangeLog
index 822f86c..d49cfa2 100644
--- a/libgst/ChangeLog
+++ b/libgst/ChangeLog
@@ -1,5 +1,11 @@
 2013-10-07  Paolo Bonzini  <address@hidden>
 
+       * libgst/dict.inl: In index_oop_spec and index_oop_put_spec,
+       move index decrement after the scaling by sizeof(type) and the
+       overflow test.  This prepares for fixing the overflow test.
+
+2013-10-07  Paolo Bonzini  <address@hidden>
+
        * libgst/genvm-parse.def: Emit definitions for UNDO_PREPARE_STACK.
        * libgst/vm.def: Wrap calls to _gst_make_block_closure with
        PREPARE_STACK and UNDO_PREPARE_STACK.  Otherwise, the sp
diff --git a/libgst/dict.inl b/libgst/dict.inl
index 434906a..3b029b0 100644
--- a/libgst/dict.inl
+++ b/libgst/dict.inl
@@ -985,8 +985,6 @@ index_oop_spec (OOP oop,
   if UNCOMMON (index < 1)
     return (NULL);
 
-  index--;
-
 #define DO_INDEX_OOP(type, dest)                                       \
     /* Find the number of bytes in the object.  */                     \
     maxByte = NUM_WORDS (object) * sizeof (PTR);                       \
@@ -998,9 +996,11 @@ index_oop_spec (OOP oop,
       + (instanceSpec >> ISP_NUMFIXEDFIELDS) * sizeof (PTR);           \
                                                                        \
     /* Check that we're on bounds.  */                                 \
-    if UNCOMMON (index + sizeof(type) > maxByte)                       \
+    if UNCOMMON (index > maxByte)                                      \
       return (NULL);                                                   \
                                                                        \
+    index -= sizeof(type);                                             \
+                                                                       \
     /* Use a cast if unaligned accesses are supported, else memcpy.  */        
\
     src = ((char *) object->data) + index;                             \
     if (sizeof (type) <= sizeof (PTR))                                 \
@@ -1085,10 +1085,10 @@ index_oop_spec (OOP oop,
       case GST_ISP_POINTER:
         maxIndex = NUM_WORDS (object);
         index += instanceSpec >> ISP_NUMFIXEDFIELDS;
-        if UNCOMMON (index >= maxIndex)
+        if UNCOMMON (index > maxIndex)
          return (NULL);
 
-        return (object->data[index]);
+        return (object->data[index - 1]);
     }
 #undef DO_INDEX_OOP
 
@@ -1117,8 +1117,6 @@ index_oop_put_spec (OOP oop,
   if UNCOMMON (index < 1)
     return (false);
 
-  index--;
-
 #define DO_INDEX_OOP_PUT(type, cond, src)                              \
     if COMMON (cond)                                                   \
       {                                                                        
\
@@ -1132,9 +1130,11 @@ index_oop_put_spec (OOP oop,
           + (instanceSpec >> ISP_NUMFIXEDFIELDS) * sizeof (PTR);       \
                                                                        \
         /* Check that we're on bounds.  */                             \
-        if UNCOMMON (index + sizeof(type) > maxByte)                   \
+        if UNCOMMON (index > maxByte)                                  \
           return (false);                                              \
                                                                        \
+        index -= sizeof(type);                                         \
+                                                                       \
         /* Use a cast if unaligned accesses are ok, else memcpy.  */   \
         if (sizeof (type) <= sizeof (PTR))                             \
          {                                                             \
@@ -1251,10 +1251,10 @@ index_oop_put_spec (OOP oop,
       case GST_ISP_POINTER:
         maxIndex = NUM_WORDS (object);
         index += instanceSpec >> ISP_NUMFIXEDFIELDS;
-        if UNCOMMON (index >= maxIndex)
+        if UNCOMMON (index > maxIndex)
          return (false);
 
-        object->data[index] = value;
+        object->data[index - 1] = value;
         return (true);
     }
 #undef DO_INDEX_OOP_PUT
-- 
1.8.3.1





reply via email to

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