msvcrt: Avoid depending on signed variable overflow in parse_double.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2020-05-01 11:58:11 +02:00 committed by Alexandre Julliard
parent 9733b821e0
commit 65642f4bb7
1 changed files with 6 additions and 2 deletions

View File

@ -549,8 +549,10 @@ static double strtod16(MSVCRT_wchar_t get(void *ctx), void unget(void *ctx),
}
if(nch>='0' && nch<='9') {
while(nch>='0' && nch<='9') {
if(e>INT_MAX/10 || (e=e*10+nch-'0')<0)
if(e>INT_MAX/10 || e*10>INT_MAX-nch+'0')
e = INT_MAX;
else
e = e*10+nch-'0';
nch = get(ctx);
}
if((nch!=MSVCRT_WEOF) && (nch < '0' || nch > '9')) unget(ctx);
@ -827,8 +829,10 @@ double parse_double(MSVCRT_wchar_t (*get)(void *ctx), void (*unget)(void *ctx),
if(nch>='0' && nch<='9') {
while(nch>='0' && nch<='9') {
if(e>INT_MAX/10 || (e=e*10+nch-'0')<0)
if(e>INT_MAX/10 || e*10>INT_MAX-nch+'0')
e = INT_MAX;
else
e = e*10+nch-'0';
nch = get(ctx);
}
if(nch != MSVCRT_WEOF) unget(ctx);