Re: Strange machine-level exception
- Posted by Daryl Border <darylb5 at aol.com> Jun 20, 2007
- 566 views
Pete Lomax wrote: > > Bernie Ryan wrote: > > > > > > Looking at the source in be_runtime.c for find_from. > > > > It seems that the code is testing for the value of the length for > > > > the full sequence instead of the length of the sequence from the > > > > starting point of the find to the end of the sequence. > > > > Maybe I'am wrong ? > > That's what I thought too. A further test confirms this beyond any remaining > doubt: > }}} <eucode> > sequence x > x={1,2,3,4,{5}} > x=x[1..3] > ?find_from({5},x,3) > </eucode> {{{ > and it prints 5 which is obvious nonsense as length(x) is now 3. > > Regards, > Pete I agree the routine is searching memory beyond the end of the sequence. There is another problem with both find_from and match_from. Neither routine performs lower bounds checking on the third argument. If a negative value is passed to the routines, they will search memory before the beginning of the sequence which may also crash the interpreter. I also think the routines should return -1 for an out of bounds condition instead of 0. The current behavior makes a return value of 0 ambiguous.