shell/math: add note on ERANGE
function old new delta evaluate_string 1488 1478 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
10cce8ae35
commit
79b90cbece
1 changed files with 11 additions and 4 deletions
15
shell/math.c
15
shell/math.c
|
@ -667,6 +667,7 @@ evaluate_string(arith_state_t *math_state, const char *expr)
|
||||||
/* At this point, we're done with the expression */
|
/* At this point, we're done with the expression */
|
||||||
if (numstackptr != numstack + 1) {
|
if (numstackptr != numstack + 1) {
|
||||||
/* if there is not exactly one result, it's bad */
|
/* if there is not exactly one result, it's bad */
|
||||||
|
/* Example: $((1 2)) */
|
||||||
goto syntax_err;
|
goto syntax_err;
|
||||||
}
|
}
|
||||||
return numstack->val;
|
return numstack->val;
|
||||||
|
@ -691,9 +692,10 @@ evaluate_string(arith_state_t *math_state, const char *expr)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dbg("[%d] var:IGNORED", (int)(numstackptr - numstack));
|
dbg("[%d] var:IGNORED", (int)(numstackptr - numstack));
|
||||||
numstackptr->var_name = NULL;
|
|
||||||
numstackptr->val = 0; //paranoia, probably not needed
|
|
||||||
expr = p;
|
expr = p;
|
||||||
|
numstackptr->var_name = NULL;
|
||||||
|
push_num0:
|
||||||
|
numstackptr->val = 0;
|
||||||
}
|
}
|
||||||
push_num:
|
push_num:
|
||||||
numstackptr++;
|
numstackptr++;
|
||||||
|
@ -717,8 +719,13 @@ evaluate_string(arith_state_t *math_state, const char *expr)
|
||||||
*/
|
*/
|
||||||
if (isalnum(*expr) || *expr == '_')
|
if (isalnum(*expr) || *expr == '_')
|
||||||
goto syntax_err;
|
goto syntax_err;
|
||||||
if (errno)
|
if (errno) {
|
||||||
numstackptr->val = 0; /* bash compat */
|
// TODO: bash 5.2.15 does not catch ERANGE (some older version did?).
|
||||||
|
// $((99999999999999999999)) is 7766279631452241919 (the 64-bit truncated value).
|
||||||
|
// Our BASE# code does this as well: try $((10#99999999999999999999)),
|
||||||
|
// but the "ordinary" code path with strtoull() does not do this.
|
||||||
|
goto push_num0; /* bash compat */
|
||||||
|
}
|
||||||
goto push_num;
|
goto push_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue