From owner-svn-src-head@FreeBSD.ORG Sat May 10 17:42:22 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5FC58EFB; Sat, 10 May 2014 17:42:22 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 348D295E; Sat, 10 May 2014 17:42:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4AHgMd5046805; Sat, 10 May 2014 17:42:22 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4AHgL9g046801; Sat, 10 May 2014 17:42:21 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201405101742.s4AHgL9g046801@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 10 May 2014 17:42:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r265844 - in head/bin/sh: . tests/builtins X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 May 2014 17:42:22 -0000 Author: jilles Date: Sat May 10 17:42:21 2014 New Revision: 265844 URL: http://svnweb.freebsd.org/changeset/base/265844 Log: sh: Don't discard getopts state on unknown option or missing argument. When getopts finds an invalid option or a missing option-argument, it should not reset its state and should set OPTIND as normal. This is an old ash bug that was fixed long ago in dash. Our behaviour now matches most other shells. Added: head/bin/sh/tests/builtins/getopts6.0 (contents, props changed) head/bin/sh/tests/builtins/getopts7.0 (contents, props changed) Modified: head/bin/sh/options.c Modified: head/bin/sh/options.c ============================================================================== --- head/bin/sh/options.c Sat May 10 17:03:33 2014 (r265843) +++ head/bin/sh/options.c Sat May 10 17:42:21 2014 (r265844) @@ -480,7 +480,7 @@ atend: INTON; } c = '?'; - goto bad; + goto out; } if (*++q == ':') q++; @@ -501,7 +501,7 @@ atend: INTON; c = '?'; } - goto bad; + goto out; } if (p == **optnext) @@ -511,14 +511,10 @@ atend: } else setvarsafe("OPTARG", "", 0); - ind = *optnext - optfirst + 1; - goto out; -bad: - ind = 1; - *optnext = NULL; - p = NULL; out: + if (*optnext != NULL) + ind = *optnext - optfirst + 1; *optptr = p; fmtstr(s, sizeof(s), "%d", ind); err |= setvarsafe("OPTIND", s, VNOFUNC); Added: head/bin/sh/tests/builtins/getopts6.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/getopts6.0 Sat May 10 17:42:21 2014 (r265844) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +set -- -x -y +getopts :x var || echo "First getopts bad: $?" +getopts :x var +r=$? +[ r != 0 ] && [ "$OPTIND" = 3 ] Added: head/bin/sh/tests/builtins/getopts7.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/getopts7.0 Sat May 10 17:42:21 2014 (r265844) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +set -- -x +getopts :x: var +r=$? +[ r != 0 ] && [ "$OPTIND" = 2 ]