From c8513fcb7a0e57bf281bd3756069a6f039adc8f1 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Tue, 5 Jan 2021 23:08:20 +0000 Subject: [PATCH] Arith: informative err msg on '.' radix point in non-'.' locales Scripts that use floating point shell arithmetic confusingly fail with 'arithmetic syntax error' when running in a locale that uses ',' as the radix point, because '.' is generally assumed by scripts. The error message is confounding as the problem is not a syntax error but a locale that is incompatible with the script. src/cmd/ksh93/sh/arith.c: - If the locale's radix point is not '.' but a '.' is found in its place, issue an informative error message that instructs setting LC_NUMERIC=C. Resolves: https://github.com/ksh93/ksh/issues/145 --- src/cmd/ksh93/sh/arith.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/ksh93/sh/arith.c b/src/cmd/ksh93/sh/arith.c index cea06248a..11c2ff946 100644 --- a/src/cmd/ksh93/sh/arith.c +++ b/src/cmd/ksh93/sh/arith.c @@ -388,6 +388,7 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl else { char lastbase=0, *val = xp, oerrno = errno; + const char radix = GETDECIMAL(0); lvalue->eflag = 0; errno = 0; if(shp->bltindata.bnode==SYSLET && !sh_isoption(SH_LETOCTAL)) @@ -418,7 +419,9 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl c='e'; else c = *str; - if(c==GETDECIMAL(0) || c=='e' || c == 'E' || lastbase == 16 && (c == 'p' || c == 'P')) + if(c=='.' && radix!='.') + errormsg(SH_DICT,ERROR_exit(1),"%s: radix point '.' requires LC_NUMERIC=C",val); + if(c==radix || c=='e' || c == 'E' || lastbase == 16 && (c == 'p' || c == 'P')) { lvalue->isfloat=1; r = strtold(val,&str);