Fix an edge case when parsing large numbers which resulted in inconsistent

results between an expression that refers to a variable by name and the
same expression that includes the same variable by value.

Submitted by:	se@
MFC after:	1 week
This commit is contained in:
Dag-Erling Smørgrav 2019-01-09 09:36:54 +00:00
parent 10731c54b6
commit a96301b673
3 changed files with 22 additions and 2 deletions

View File

@ -59,8 +59,7 @@
*/
typedef intmax_t arith_t;
#define ARITH_FORMAT_STR "%" PRIdMAX
#define atoarith_t(arg) strtoimax(arg, NULL, 0)
#define strtoarith_t(nptr, endptr, base) strtoimax(nptr, endptr, base)
#define strtoarith_t(nptr, endptr, base) (intmax_t)strtoumax(nptr, endptr, base)
#define ARITH_MIN INTMAX_MIN
#define ARITH_MAX INTMAX_MAX

View File

@ -21,6 +21,7 @@ ${PACKAGE}FILES+= arith11.0
${PACKAGE}FILES+= arith12.0
${PACKAGE}FILES+= arith13.0
${PACKAGE}FILES+= arith14.0
${PACKAGE}FILES+= arith15.0
${PACKAGE}FILES+= assign1.0
${PACKAGE}FILES+= cmdsubst1.0
${PACKAGE}FILES+= cmdsubst2.0

View File

@ -0,0 +1,20 @@
# $FreeBSD$
failures=0
check() {
if [ $(($1)) != $2 ]; then
failures=$((failures+1))
echo "For $1, expected $2 actual $(($1))"
fi
}
XXX=-9223372036854775808
check "XXX" -9223372036854775808
check "XXX - 1" 9223372036854775807
check $(($XXX - 1)) 9223372036854775807
check $(($XXX - 2)) 9223372036854775806
check $((0x8000000000000000 == 0x7fffffffffffffff)) \
0
exit $((failures != 0))