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
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=342880
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))