Email List: Xaustin-review-lX
[All Lists]

Defect in XRAT 2.4.6 Arithmetic Expansion

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Defect in XRAT 2.4.6 Arithmetic Expansion
From: yyyy@xxxxxxxxx
Date: Wed, 25 Jun 2003 10:08:04 +0100 (BST)
        Defect report from : Wartan Hachaturow , Lanit-Tercom, Inc.

(Please direct followup comments direct to yyyyyyyyyyyyyy@xxxxxxxxxxxxx)

@ page 0 line 0 section 2.4.6 Arithmetic Expansion comment {42}

Problem:

Edition of Specification (Year): 2003

Defect code :  3. Clarification required

The problem discussed is about standart behaviour of POSIX-compatible shell 
during
arithmetic evaluation in $(()).
Initially, the problem was arised in freebsd-standarts, with the following bug 
report
against FreeBSD's /bin/sh (ash):
                                                                                
               "/bin/sh implements only a subset of the operators in $(( ... )) 
arithmetic.
    It also does not understand variable names in arithmetic expressions.
                                                                                
                 This missing feature makes it impossible to run the 
OpenGroup's POSIX                      validation test suite because the 
configuration process for the test suite
    expects a POSIX system shell and makes heavy use of $((var += number)).
      
    $ /bin/sh                                                                   
               $ a=1 
    $ echo $((a += 1))                    # should echo 2 and increment a       
               arith: syntax error: "a += 1"
"

The tests in question are TET3.6 Environment, which have that kind of code:
                                                                                
           yyyyyyy@xxxxxxx:/tmp $ fgrep '$((' src/posix_sh/api/tcm.sh
                         : $((tet_l1_iccount += 1))
                 while test $((tet_l1_tpnum += 1)) -le $tet_tpcount             
                                    : $((tet_l1_tpcount += 1))                  
                                          ...                                   
                                                                                
                                            Let's look at the 
http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_06_04,
 which is "Arithmetic Expansion":

"Next, the shell shall treat this as an arithmetic expression and substitute 
the value of the expression. The arithmetic expression shall be processed 
according to the rules given in Arithmetic Precision and Operations , with the 
following exceptions:
      Only signed long integer arithmetic is required.
      Only the decimal-constant, octal-constant, and hexadecimal-constant 
constants specified in the ISO C standard, Section 6.4.4.1 are required to be 
recognized as constants.
      The sizeof() operator and the prefix and postfix "++" and "--" operators 
are not required.
      Selection, iteration, and jump statements are not supported."

Now, let's go to Arithmetic Precision and Operations, which is 
http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap01.html#tag_01_07_02_01
 :

"Integer variables and constants, including the values of operands and 
option-arguments, used by the standard utilities listed in this volume of IEEE 
Std 1003.1-2001 shall be implemented as equivalent to the ISO C standard signed 
long data type; floating point shall be implemented as equivalent to the ISO C 
standard double type. Conversions between types shall be as described in the 
ISO C standard. All variables shall be initialized to zero if they are not 
otherwise assigned by the input to the application."

So, here I see the requirement for "integer variables" and assignment operators 
like "+=", which clearly needs variables support.

I have filed the same bug against Debian's version of ash shell, which is 
maintained
but one of the Austin group members, Herbert Xu. He claimed that POSIX shell 
should
only support constant arithmetics, and pointed me to the rationale for section 
2.6.4,
which is here: 
http://www.opengroup.org/onlinepubs/007904975/xrat/xcu_chap02.html

"The syntax and semantics for arithmetic were changed for the ISO/IEC 
9945-2:1993 standard. The language is essentially a pure arithmetic evaluator 
of constants and operators (excluding assignment) and represents a simple 
subset of the previous arithmetic language (which was derived from the 
KornShell "(())" construct). The syntax was changed from that of a command 
denoted by ((expression)) to an expansion denoted by $((expression)). The new 
form is a dollar expansion ( '$' ) that evaluates the expression and 
substitutes the resulting value."

So, rationale tends to agree with Herbert that only evaluation of constants and 
operators is required for the compatible shell.
In this case I should give preference to the standart itself, but I feel like
I need to have some clarification on the subject. Is Rationale for that section
outdated, or have I misread the standart? If the latter, why OpenGroup's own
tests use this non-standart feature?


Action:

If I am right, and rationale is simply outdated, then 
the whole rationale section 2.6.4 should be rewritten to conform to standart 
itself.

<Prev in Thread] Current Thread [Next in Thread>
  • Defect in XRAT 2.4.6 Arithmetic Expansion, wart <=