NetBSD Problem Report #50959
From kre@munnari.OZ.AU Sat Mar 12 18:11:34 2016
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 76BD37A13C
for <gnats-bugs@www.NetBSD.org>; Sat, 12 Mar 2016 18:11:34 +0000 (UTC)
Message-Id: <201603121811.u2CIB7im019170@andromeda.noi.kre.to>
Date: Sun, 13 Mar 2016 01:11:07 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@www.NetBSD.org
Subject: /bin/sh does not support 0Xxxx literal constants in $(( )) evaluation
X-Send-Pr-Version: 3.95
>Number: 50959
>Category: bin
>Synopsis: /bin/sh does not support 0Xxxx literal constants in $(( )) evaluation
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Mar 12 18:15:00 +0000 2016
>Closed-Date: Mon Apr 04 12:38:44 +0000 2016
>Last-Modified: Mon Apr 04 12:38:44 +0000 2016
>Originator: Robert Elz
>Release: NetBSD 7.99.26 (anything to date of this PR)
>Organization:
>Environment:
System: NetBSD andromeda.noi.kre.to 7.99.26 NetBSD 7.99.26 (VBOX64-1.1-20160128) #43: Thu Jan 28 16:09:08 ICT 2016 kre@onyx.coe.psu.ac.th:/usr/obj/current/kernels/amd64/VBOX64 amd64
Architecture: x86_64
Machine: amd64
>Description:
$(( )) expressions are required to allow decimal, hex, and
octal constants (as operands of the expression - the result
is always decimal.)
NetBSD's /bin/sh does all of that, provided that the hex constant
form uses a lower case 'x' in the leading 0x, rather than upper
case 'X'.
Further, if the hex constant is assigned to a variable, and the
variable name is used in an expression, then hex constants work
regardless of whether it is 0x or 0X. Not very consistent.
>How-To-Repeat:
/bin/sh -c 'echo $(( 0x1 )); echo $(( 0X1 ))' 2>&1
1
sh: arith: syntax error: " 0X1 "
/bin/sh -c 'V=0x1; W=0X1; echo $(( V )) $(( W ))'
1 1
/bin/sh -c 'V=0x1; W=0X1; echo $(( $V )) $(( $W ))'
sh: arith: syntax error: " 0X1 "
Note that in the second, V and W have string values, they are
only converted to integers when used inside $(()). The third
example illustrates that (there's no output in that case as
the whole echo command fails when the syntax error is detected,
but the $V expression would be just fine). This case is just
the same thing as the first of course.
>Fix:
Trivial to fix... already done in my copy, this is another of the
/bin/sh placeholder PRs just to reference when the fix is committed.
>Release-Note:
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/50959 CVS commit: src/bin/sh
Date: Wed, 16 Mar 2016 11:41:56 -0400
Module Name: src
Committed By: christos
Date: Wed Mar 16 15:41:55 UTC 2016
Modified Files:
src/bin/sh: arith_lex.l
Log Message:
PR bin/50959 - allow consistent use of 0X hex constants (not just 0x)
(from kre)
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/bin/sh/arith_lex.l
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Mon, 04 Apr 2016 12:38:44 +0000
State-Changed-Why:
Fixed, thanks!
>Unformatted:
(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-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.