Subject: Re: bin/20259: sort(1) numeric sort incorrect with -kn
To: Giles Lean <email@example.com>
From: Greg A. Woods <firstname.lastname@example.org>
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; <email@example.com>; <firstname.lastname@example.org>
Planix, Inc. <email@example.com>; VE3TCP; Secrets of the Weird <firstname.lastname@example.org>