History log of /freebsd-current/bin/sh/arith_yacc.c
Revision Date Author Comments
# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# aac5464b 10-Feb-2019 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Restore $((x)) error checking after fix for $((-9223372036854775808))

SVN r342880 was designed to fix $((-9223372036854775808)) and things like
$((0x8000000000000000)) but also broke error detection for values of
variables without dollar sign ($((x))).

For compatibility, overflow in plain literals continues to be ignored and
the value is clamped to the boundary (except 9223372036854775808 which is
changed to -9223372036854775808).

Reviewed by: se (although he would like error checking to be removed)
MFC after: 2 weeks
X-MFC-with: r342880
Differential Revision: https://reviews.freebsd.org/D18926


# dd6d480a 20-Aug-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove two redundant (uintmax_t) casts.

Submitted by: jmallett


# d5b14891 15-Aug-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Mask off shift distance (<< and >>) in arithmetic.

In C, shift distances equal to or larger than the number of bits in the
operand result in undefined behaviour. As part of eliminating undefined
behaviour in arithmetic, mask off the distance like Java and JavaScript
specify and C on x86 usually does.

Assumption: conversion from unsigned to signed retains the two's complement
bits.
Assumption: uintmax_t has no padding bits.


# b0762e49 01-Jun-2014 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Avoid undefined behaviour shifting negative values left in arithmetic.

With i386 base clang, arith_yacc.o remains unchanged.


# 2fae4c3d 25-Jan-2012 Philippe Charnier <charnier@FreeBSD.org>

Add prototypes, ANSIfy functions definitions to reduce WARNS=6 output.


# 876f9b78 08-Nov-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove undefined behaviour due to overflow in +/-/* in arithmetic.

With i386 base gcc and i386 base clang, arith_yacc.o remains unchanged.


# 4004e05e 26-Jun-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Include <limits.h> instead of non-standard <sys/limits.h>.


# 8d5a1430 27-May-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Remove the "exp" builtin.

The "exp" builtin is undocumented, non-standard and not very useful.

If exp's return value is not used, something like
VAR=$(exp EXPRESSION)
is equivalent to
VAR=$((EXPRESSION))
except that errors in the expression are fatal and quoting special
characters is not needed in the latter case.

If exp's return value is used, something like
if exp EXPRESSION >/dev/null
can be replaced by
if [ $((EXPRESSION)) -ne 0 ]
with similar differences.

The exp-run showed that "let" is close enough to bash's and ksh's builtin
that removing it would break a few ports. Therefore, "let" remains in 9.x.

PR: bin/104432
Exp-run done by: pav (with some other sh(1) changes)


# 3937fc9c 04-May-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Apply set -u to variables in arithmetic.

Note that this only applies to variables that are actually used.
Things like (0 && unsetvar) do not cause an error.

Exp-run done by: pav (with some other sh(1) changes)


# 976018d2 05-Mar-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Fix some warnings in code for arithmetic expressions.

Submitted by: eadler


# e9749129 12-Feb-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Detect dividing the smallest integer by -1.

This overflows and on some architectures such as amd64 it generates SIGFPE.
Generate an error on all architectures.


# 6262b84e 08-Feb-2011 Jilles Tjoelker <jilles@FreeBSD.org>

sh: Import arithmetic expression code from dash.

New features:
* proper lazy evaluation of || and &&
* ?: ternary operator
* executable is considerably smaller (8K on i386) because lex and yacc are
no longer used

Differences from dash:
* arith_t instead of intmax_t
* imaxdiv() not used
* unset or null variables default to 0
* let/exp builtin (undocumented, will probably be removed later)

Obtained from: dash