Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: src/bin/sh



Module Name:    src
Committed By:   kre
Date:           Sat Dec 13 08:19:41 UTC 2025

Modified Files:
        src/bin/sh: arithmetic.c

Log Message:
Fix a bug in syntax of the ?: operator

The ?: operator has 3 sub-expressions.  The first (before the ?)
is an "or-list" (generic conditional expression).  The third,
after the : is another cond-expr (might be another ?: operator).

Those we handled properly.

The middle expression however, according to the C standard,
which is what the shell is supposed (to the extent it is
required to implement) to support, can be any expression at all.

We had that correct when an assignment was the highest level
(or if you prefer, lowest precedence) operators accepted by the
syntax (which is all that is required by POSIX).

When the ',' operator was added - which has assignments as its
basic sub-expressions, and so became the shell's definition of
an arithmetic expression, that is, the new highest level (lowest
precedence) operator, the ?: operator was not adjusted to allow
comma-lists as the middle expression - as it never occurred to me
that that should now be possible.    Now I know better.

Or to be less abstract, previously $(( exp ? a , b : exp )) used to
fail (and a test case of that just added to the shell's arithmetic ATF
tests will fail because of that).  After this, that will no longer
fail, instead will be processed correctly.

The actual change is about 3% the size of this commit message.

XXX pullup -9 -10 -11


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/bin/sh/arithmetic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




Home | Main Index | Thread Index | Old Index