Subject: Re: bin/20259: sort(1) numeric sort incorrect with -kn
To: Giles Lean <giles@nemeton.com.au>
From: Greg A. Woods <woods@weird.com>
List: netbsd-bugs
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.
> 
> No.

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
test case):

	(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)
	    at init.c:165
	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;            <g.a.woods@ieee.org>;           <woods@robohack.ca>
Planix, Inc. <woods@planix.com>; VE3TCP; Secrets of the Weird <woods@weird.com>