Skip to content
This repository
Browse code

sclang: fix Array-*slide crash

fixes #645

Signed-off-by: Tim Blechmann <tim@klingt.org>
  • Loading branch information...
commit a4c33b95dbd3ad5e5c91687d29376e17353c5c64 1 parent d3a9698
Tim Blechmann timblechmann authored

Showing 1 changed file with 7 additions and 5 deletions. Show diff stats Hide diff stats

  1. +7 5 lang/LangPrimSource/PyrArrayPrimitives.cpp
12 lang/LangPrimSource/PyrArrayPrimitives.cpp
@@ -1973,7 +1973,7 @@ int prArraySlide(struct VMGlobals *g, int numArgsPushed)
1973 1973 {
1974 1974 PyrSlot *a, *b, *c, *slots;
1975 1975 PyrObject *obj1, *obj2;
1976   - int h, i, j, k, n, m, numslots, numwin;
  1976 + int h, i, j, k, numslots, numwin;
1977 1977
1978 1978 a = g->sp - 2;
1979 1979 b = g->sp - 1;
@@ -1983,15 +1983,17 @@ int prArraySlide(struct VMGlobals *g, int numArgsPushed)
1983 1983
1984 1984 obj1 = slotRawObject(a);
1985 1985 slots = obj1->slots;
1986   - m = slotRawInt(b);
1987   - n = slotRawInt(c);
  1986 + int m = slotRawInt(b);
  1987 + int n = slotRawInt(c);
  1988 + if (n <= 0)
  1989 + return errFailed;
  1990 +
1988 1991 numwin = (obj1->size + n - m) / n;
1989 1992 numslots = numwin * m;
1990 1993 obj2 = instantiateObject(g->gc, obj1->classptr, numslots, false, true);
1991 1994 for (i=h=k=0; i<numwin; ++i,h+=n) {
1992   - for (j=h; j<m+h; ++j) {
  1995 + for (j=h; j<m+h; ++j)
1993 1996 slotCopy(&obj2->slots[k++],&slots[j]);
1994   - }
1995 1997 }
1996 1998 obj2->size = k;
1997 1999 SetRaw(a, obj2);

0 comments on commit a4c33b9

Please sign in to comment.
Something went wrong with that request. Please try again.