Bug 740193: Foreground selection causes segfault

Create leaves if max-min <= limits or pivot == max
otherwise it is possible to start an infinite recursion
or to access a buffer beyond its end.