SignedByteArray.st
changeset 19413 2337a2d9861c
parent 19176 7c7f2efe0f72
child 19935 feb65418c896
--- a/SignedByteArray.st	Tue Mar 22 23:15:35 2016 +0100
+++ b/SignedByteArray.st	Wed Mar 23 14:21:37 2016 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2016 by eXept Sofware AG
               All Rights Reserved
@@ -160,7 +162,7 @@
 !
 
 beUnsigned
-    "make mayself unsigned.
+    "make myself unsigned.
      elements < 0 are converted to positive numbers."
 
     self class == SignedByteArray ifTrue:[
@@ -330,16 +332,17 @@
         max = -128;
         index = 0;
         len = __qSize(self) - OHDR_SIZE;
-
-        for (cp = __ByteArrayInstPtr(self)->ba_element; ++index <= len; cp++) {
-            int byte = *cp;
+        if (len > 0) {
+            for (cp = __ByteArrayInstPtr(self)->ba_element; ++index <= len; cp++) {
+                int byte = *cp;
 
-            if (byte > max) {
-                max = byte;
-                if (byte == 127) break;
+                if (byte > max) {
+                    max = byte;
+                    if (byte == 127) break;
+                }
             }
+            RETURN ( __mkSmallInteger(max) );
         }
-        RETURN ( __mkSmallInteger(max) );
     }
 %}.
     ^ super max
@@ -348,6 +351,8 @@
      #[1 2 3 -11 2 3 1 2 19] max
      #(-1 -2 -3 -4) asSignedByteArray max
      #() asSignedByteArray max
+     #[] max   
+     #() max   
     "
 ! !
 
@@ -411,6 +416,8 @@
     "
      #(-1 2 3 -4 5 6 7 8 9 0 1 2 3 4 5) asSignedByteArray indexOf:0 startingAt:1
      #(-1 2 3 -4 5 6 7 8 9 0 1 2 3 4 5) asSignedByteArray indexOf:-4 startingAt:1
+     #() asSignedByteArray indexOf:-4 startingAt:1  
+     #() indexOf:-4 startingAt:1     
     "
 ! !