www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - sort bug: Goes outside of limits of array

dmd v0.100, Fedora Core 1 Linux.

I was getting some segfaults while sorting arrays of real's.  So I 
implemented by own copy of the comparison function for real's and found 
that this eventually gets called where one of the things being compared 
is outside of the limits of the array.

I get assert failure on the 4th assertion.  Here's the call stack on 
that assert, as reported by gdb:









Here's the code that I ran:
 import std.stdio;
 
 void *sort_min; void *sort_max;
 extern(C) int _D7ti_real10TypeInfo_e7compareFPvPvZi(void *p1,void *p2) {
   writef("min=%x max=%x p1=%x p2=%x\n", cast(uint)sort_min,
cast(uint)sort_max, cast(uint)p1, cast(uint)p2); fflush(null);
 
   assert(sort_min <= p1);
   assert(p1 <= sort_max);
   assert(sort_min <= p2);
   assert(p2 <= sort_max);
 
   int ret = cast(int)(*cast(real *)p1 - *cast(real *)p2);
   return ret;
 }
 
 void main() {
   while(1) {
     real[200] foo;
     sort_min = &foo[0]; sort_max = &foo[length-1];
     foo.sort;
     writef("\n");
   }
 }
Aug 23 2004