1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

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
This commit is contained in:
Martijn Dekker 2021-01-05 23:08:20 +00:00
parent d1483150ab
commit c8513fcb7a

View file

@ -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);