Обсуждение: bug in function strtoint, on Windows OS won't report ERANGE

Поиск
Список
Период
Сортировка

bug in function strtoint, on Windows OS won't report ERANGE

От
Miron Berlin
Дата:
Dear Postgres Dev Team,


Functionstrtoint has a bug. It would not report ERANGE on Windows OS compiled with Microsoft Visual Studio compiler.
To work correctly please replace call to strtol with call to strtoll ( please note two letters l on the right hand side ).
This function should produce correct data type on all available platforms.
In addition, please modify type of the variable val declared at the top of the function from long to an portable 64 bit long integer.
For example long long.

Please note, an substitution of function strtoint with strtol sets errno as expected on Windows platform.
Please note, fixing this bug may have wide impact due to frequent use of function strtoint in various lexer(s).

Thanks,

Miron


Re: bug in function strtoint, on Windows OS won't report ERANGE

От
Tom Lane
Дата:
Miron Berlin <mironatpro@hotmail.com> writes:
> Functionstrtoint has a bug. It would not report ERANGE on Windows OS compiled with Microsoft Visual Studio compiler.

Have you actually tested that?  AFAICS, the code as given works
perfectly fine on platforms where long is the same width as int.
The lines

    if (val != (int) val)
        errno = ERANGE;

are dead code then (and possibly will be elided by the compiler),
but it doesn't matter because then strtol can be expected to
set ERANGE properly for values outside the int range.

Possibly it'd be worth adding a comment to point this out.

            regards, tom lane