Subject: Re: bin/20259: sort(1) numeric sort incorrect with -kn
To: Giles Lean <firstname.lastname@example.org>
From: Greg A. Woods <email@example.com>
Date: 02/10/2003 15:48:28
[ On Monday, February 10, 2003 at 11:25:01 (+1100), Giles Lean wrote: ]
> Subject: Re: bin/20259: sort(1) numeric sort incorrect with -kn
> Greg Woods wrote:
> > The problem is no doubt rooted in getopt(2) being a lot too lax.
Well, OK, maybe not exactly, BUT....
> > and that should have caused the setfield() function to fail due to an
> > invalid field-spec.
> setfield() calls setcolumn() which in turn calls optval() in a loop
> to handle the field modifiers, per the following code in init.c:
Irrelevant. You're not paying attention to what is being passed to
setfield(). You'll find that it's the string "1rn" (for at least your
(gdb) run -k1rn
Starting program: /work/woods/m-NetBSD-1.6/usr.bin/sort/./sort -k1rn
Breakpoint 1, setfield (pos=0xbfbfd077 "1rn", cur_fld=0xbfbfcce8, gflag=0)
165 if (++nfields == ND)
Obviously "1rn" is not a valid field-spec.
Obviously getopt() never sees the '-r' and '-n' flags, so obviously if
setfield() doesn't bail out with an error then you'll see the output in
the wrong order.
Greg A. Woods
+1 416 218-0098; <firstname.lastname@example.org>; <email@example.com>
Planix, Inc. <firstname.lastname@example.org>; VE3TCP; Secrets of the Weird <email@example.com>