NetBSD Problem Report #39446

From www@NetBSD.org  Mon Sep  1 10:54:06 2008
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id E72EB63BC96
	for <gnats-bugs@gnats.netbsd.org>; Mon,  1 Sep 2008 10:54:06 +0000 (UTC)
Message-Id: <20080901105406.BB35163BC80@narn.NetBSD.org>
Date: Mon,  1 Sep 2008 10:54:06 +0000 (UTC)
From: cheusov@tut.by
Reply-To: cheusov@tut.by
To: gnats-bugs@NetBSD.org
Subject: /bin/sh: test <NUMBER> <op> <NUMBER> improvements
X-Send-Pr-Version: www-1.0

>Number:         39446
>Category:       bin
>Synopsis:       /bin/sh: test <NUMBER> <op> <NUMBER> improvements
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 01 10:55:00 +0000 2008
>Closed-Date:    Thu Sep 11 15:42:23 +0000 2008
>Last-Modified:  Thu Sep 11 15:42:23 +0000 2008
>Originator:     Aleksey Cheusov
>Release:        NetBSD-4
>Organization:
home
>Environment:
have no access right now.
>Description:
Built-in test command shows the warning if arguments of -eq, -ne etc.
operators are not numbers but doesn't if arguments are an empty string.

  0 ~>/bin/sh -c 'test 1 -eq 1'  
  0 ~>/bin/sh -c 'test 1 -eq a' 
  test: a: bad number
  2 ~>/bin/sh -c 'test a -eq 1' 
  test: a: bad number
  2 ~>/bin/sh -c 'test "" -eq 1'
  1 ~>

I propose to display a warning and make an exit status
equal to 2 in the latter case too. bash and dash works this way.
And I think it is useful for debugging.

The same for NetBSD /bin/test command

>How-To-Repeat:

>Fix:

>Release-Note:

>Audit-Trail:
From: Aleksey Cheusov <cheusov@tut.by>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/39446: /bin/sh: test <NUMBER> <op> <NUMBER> improvements
Date: Wed, 10 Sep 2008 21:53:29 +0300

 patch for current

 Index: test.c
 ===================================================================
 RCS file: /pub/NetBSD-CVS/src/bin/test/test.c,v
 retrieving revision 1.36
 diff -u -U10 -r1.36 test.c
 --- test.c	20 Jun 2008 23:29:36 -0000	1.36
 +++ test.c	10 Sep 2008 18:52:39 -0000
 @@ -674,21 +674,21 @@
  	errno = 0;
  	r = strtoll(s, &p, 10);

  	if (errno != 0)
  	if (errno == ERANGE && (r == LLONG_MAX || r == LLONG_MIN))
  	      error("%s: out of range", s);

  	while (isspace((unsigned char)*p))
  	      p++;

 -	if (*p)
 +	if (*p || p == s)
  	      error("%s: bad number", s);

  	return r;
  }

  static int
  newerf(const char *f1, const char *f2)
  {
  	struct stat b1, b2;


 -- 
 Best regards, Aleksey Cheusov.

State-Changed-From-To: open->closed
State-Changed-By: christos@NetBSD.org
State-Changed-When: Thu, 11 Sep 2008 11:42:23 -0400
State-Changed-Why:
fixed, thanks


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.