Comment

Comment by dzeban

I guess, you're right - for naive implementation it should fall with error, not a segfault. Maybe I just add a check for realloc result.

As for qsort implementation - I was confused by glibc sources ;-) What I've found was a slow but in-place implementation, and what you've shown me is an actual implementation that invokes an in-place variant when allocation was failed:

  tmp = malloc (size);
  __set_errno (save);
  if (tmp == NULL)
    {
      /* Couldn't get space, so use the slower algorithm
         that doesn't need a temporary array.  */
      _quicksort (b, n, s, cmp, arg);
      return;
    }
Thanks for feedback!
parent dzeban 11 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton