Commit 9b8a6dc7 authored by Russ Cox's avatar Russ Cox

change array slice error to include bounds

$ 6.out
slice[5:12] of [10] array
throw: array slice
SIGSEGV: segmentation violation

R=r
DELTA=15  (13 added, 0 deleted, 2 changed)
OCL=19540
CL=19580
parent addd6fa8
...@@ -38,6 +38,19 @@ sys·newarray(uint32 nel, uint32 cap, uint32 width, Array* ret) ...@@ -38,6 +38,19 @@ sys·newarray(uint32 nel, uint32 cap, uint32 width, Array* ret)
} }
} }
static void
throwslice(uint32 lb, uint32 hb, uint32 n)
{
prints("slice[");
sys·printint(lb);
prints(":");
sys·printint(hb);
prints("] of [");
sys·printint(n);
prints("] array\n");
throw("array slice");
}
// arraysliced(old *[]any, lb uint32, hb uint32, width uint32) (ary *[]any); // arraysliced(old *[]any, lb uint32, hb uint32, width uint32) (ary *[]any);
void void
sys·arraysliced(Array* old, uint32 lb, uint32 hb, uint32 width, Array* ret) sys·arraysliced(Array* old, uint32 lb, uint32 hb, uint32 width, Array* ret)
...@@ -62,7 +75,7 @@ sys·arraysliced(Array* old, uint32 lb, uint32 hb, uint32 width, Array* ret) ...@@ -62,7 +75,7 @@ sys·arraysliced(Array* old, uint32 lb, uint32 hb, uint32 width, Array* ret)
sys·printint(old->cap); sys·printint(old->cap);
prints("\n"); prints("\n");
} }
throw("sys·arraysliced: new size exceeds old size"); throwslice(lb, hb, old->cap);
} }
// new array is inside old array // new array is inside old array
...@@ -109,7 +122,7 @@ sys·arrayslices(byte* old, uint32 nel, uint32 lb, uint32 hb, uint32 width, Arra ...@@ -109,7 +122,7 @@ sys·arrayslices(byte* old, uint32 nel, uint32 lb, uint32 hb, uint32 width, Arra
sys·printint(width); sys·printint(width);
prints("\n"); prints("\n");
} }
throw("sys·arrayslices: new size exceeds cap"); throwslice(lb, hb, nel);
} }
// new array is inside old array // new array is inside old array
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment