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

[Sc-devel] [] can cause instability: tests in primitives?



Dear all,

As discussed on sc-users today, there are at least two examples of
empty arrays being able to cause instability in the language:

 [].plot(minval: -1, maxval: 1)

 100.do{|i| [].wrapAt(i).postln }

(Run them many times if you want to cause the instabilities.)

wrapAt's primitive uses basicWrapAt(), and plot uses unlace which uses
prArrayUnlace(), both in PyrArrayPrimitives.cpp. Looks like they both
fail to account for an empty array.

Could there be some generic way to catch these problems? e.g. this
line could (I guess) return nil if empty:

 if(obj->size==0) {SetNil(a); return errNone; }

but would need slightly different versions adding to each primitive.
Any better way?

Dan