sort(1) without arguments segfaults and sorts wrong
perl -e '$x="x"x530000 ."\n";print $x,$x' | sort
perl -e '$x="x"x530000 ."\n";print $x,$x' | sort -H
and collect the core file. This happens on the
-rw-r--r-- 1 0 122 238186496 Nov 26 04:16 install44.iso
snapshot that includes the
4.4 GENERIC#1511 i386
Here's a replacement for sort(1) without arguments that doesn't
have this problem.
The goo outside of main() is for avoiding iterated use of realloc().
Memory is greedily allocated with mmap(). setrlimit() is used to
avoid an uncomfortably large core file. err() is not used because
it would use malloc().
On i386, the pages returned by mmap(...MAP_ANON...) aren't provided
by the system until they're accessed. If this isn't true on all
architectures, then this program is no good.
-- BEGIN rsort.c --
* Copyright (c) 2008 Paul Stoeber
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* rsort - sort lines with radixsort(3)
* usage: rsort
* Reads from stdin. Writes to stdout. Data must fit in memory.