oops - subclasses with instVars allowed for index-less-than-1-access
authorClaus Gittinger <cg@exept.de>
Thu, 15 Jul 1999 01:44:29 +0200
changeset 4386 ecc88f1c1169
parent 4385 dbe7d1e8c54c
child 4387 8522ae8fa0b2
oops - subclasses with instVars allowed for index-less-than-1-access
ByteArray.st
--- a/ByteArray.st	Thu Jul 15 01:38:38 1999 +0200
+++ b/ByteArray.st	Thu Jul 15 01:44:29 1999 +0200
@@ -301,19 +301,20 @@
     REGISTER int nIndex;
 
     if (__isSmallInteger(index)) {
-	indx = __intVal(index) - 1;
-	slf = self;
-	if ((cls = __qClass(slf)) != @global(ByteArray)) {
-	    if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
-		!= __MASKSMALLINT(BYTEARRAY)) {
-		goto fail;
-	    }
-	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	}
-	nIndex = __byteArraySize(slf);
-	if ((unsigned)indx < (unsigned)nIndex) {
-	    RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
-	}
+        indx = __intVal(index) - 1;
+        slf = self;
+        if ((cls = __qClass(slf)) != @global(ByteArray)) {
+            if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
+                != __MASKSMALLINT(BYTEARRAY)) {
+                goto fail;
+            }
+            if (indx < 0) goto fail;
+            indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+        }
+        nIndex = __byteArraySize(slf);
+        if ((unsigned)indx < (unsigned)nIndex) {
+            RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
+        }
     }
   fail: ;
 %}.
@@ -335,23 +336,24 @@
     REGISTER OBJ cls;
 
     if (__bothSmallInteger(index, value)) {
-	val = __intVal(value);
-	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
-	    indx = __intVal(index) - 1;
-	    slf = self;
-	    if ((cls = __qClass(slf)) != @global(ByteArray)) {
-		if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
-		    != __MASKSMALLINT(BYTEARRAY)) {
-		    goto fail;
-		}
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    }
-	    nIndex = __byteArraySize(slf);
-	    if ((unsigned)indx < (unsigned)nIndex) {
-		__ByteArrayInstPtr(slf)->ba_element[indx] = val;
-		RETURN ( value );
-	    }
-	}
+        val = __intVal(value);
+        if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
+            indx = __intVal(index) - 1;
+            slf = self;
+            if ((cls = __qClass(slf)) != @global(ByteArray)) {
+                if (((INT)__ClassInstPtr(cls)->c_flags & __MASKSMALLINT(ARRAYMASK))
+                    != __MASKSMALLINT(BYTEARRAY)) {
+                    goto fail;
+                }
+                if (indx < 0) goto fail;
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+            }
+            nIndex = __byteArraySize(slf);
+            if ((unsigned)indx < (unsigned)nIndex) {
+                __ByteArrayInstPtr(slf)->ba_element[indx] = val;
+                RETURN ( value );
+            }
+        }
     }
   fail: ;
 %}.
@@ -378,13 +380,16 @@
         byte = indx / 8;
         indx = indx % 8;
 
-        if ((cls = __qClass(slf)) != @global(ByteArray))
+        if ((cls = __qClass(slf)) != @global(ByteArray)) {
+            if (indx < 0) goto badIndex;
             byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+        }
         nIndex = __byteArraySize(slf);
         if ((unsigned)byte < (unsigned)nIndex) {
             RETURN ( __MKSMALLINT((__ByteArrayInstPtr(slf)->ba_element[byte] & (1 << indx)) != 0) );
         }
     }
+badIndex: ;
 %}.
     ^ self primitiveFailed
 
@@ -416,14 +421,17 @@
         byte = indx / 8;
         indx = indx % 8;
 
-        if ((cls = __qClass(slf)) != @global(ByteArray))
+        if ((cls = __qClass(slf)) != @global(ByteArray)) {
+            if (indx < 0) goto badIndex;
             byte += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+        }
         nIndex = __byteArraySize(slf);
         if ((unsigned)byte < (unsigned)nIndex) {
             __ByteArrayInstPtr(slf)->ba_element[byte] |= (1 << indx);
             RETURN (slf);
         }
     }
+badIndex: ;
 %}.
     ^ self primitiveFailed
 
@@ -454,15 +462,18 @@
     REGISTER OBJ cls;
 
     if (__isSmallInteger(index)) {
-	indx = __intVal(index) - 1;
-	slf = self;
-	if ((cls = __qClass(slf)) != @global(ByteArray))
-	    indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	nIndex = __byteArraySize(slf);
-	if ((unsigned)indx < (unsigned)nIndex) {
-	    RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
-	}
+        indx = __intVal(index) - 1;
+        slf = self;
+        if ((cls = __qClass(slf)) != @global(ByteArray)) {
+            if (indx < 0) goto badIndex;
+            indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+        }
+        nIndex = __byteArraySize(slf);
+        if ((unsigned)indx < (unsigned)nIndex) {
+            RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
+        }
     }
+badIndex: ;
 %}.
     ^ (super basicAt:index) asInteger
 !
@@ -480,19 +491,22 @@
     REGISTER OBJ cls;
 
     if (__bothSmallInteger(index, value)) {
-	val = __intVal(value);
-	if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
-	    indx = __intVal(index) - 1;
-	    slf = self;
-	    if ((cls = __qClass(slf)) != ByteArray)
-		indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
-	    nIndex = __byteArraySize(slf);
-	    if ((unsigned)indx < (unsigned)nIndex) {
-		__ByteArrayInstPtr(slf)->ba_element[indx] = val;
-		RETURN ( value );
-	    }
-	}
+        val = __intVal(value);
+        if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
+            indx = __intVal(index) - 1;
+            slf = self;
+            if ((cls = __qClass(slf)) != ByteArray) {
+                if (indx < 0) goto badIndex;
+                indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+            }
+            nIndex = __byteArraySize(slf);
+            if ((unsigned)indx < (unsigned)nIndex) {
+                __ByteArrayInstPtr(slf)->ba_element[indx] = val;
+                RETURN ( value );
+            }
+        }
     }
+badIndex: ;
 %}.
     ^ super basicAt:index put:value
 !
@@ -2325,5 +2339,5 @@
 !ByteArray class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.114 1999-07-10 18:33:50 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ByteArray.st,v 1.115 1999-07-14 23:44:29 cg Exp $'
 ! !