pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
bug in function strtoint, on Windows OS won't report ERANGE
2+ messages / 2 participants
[nested] [flat]

* bug in function strtoint, on Windows OS won't report ERANGE
@ 2024-03-05 12:15  Miron Berlin <mironatpro@hotmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Miron Berlin @ 2024-03-05 12:15 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

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

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: bug in function strtoint, on Windows OS won't report ERANGE
@ 2024-03-05 15:42  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Miron Berlin <mironatpro@hotmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2024-03-05 15:42 UTC (permalink / raw)
  To: Miron Berlin <mironatpro@hotmail.com>; +Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-03-05 15:42 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 12:15 bug in function strtoint, on Windows OS won't report ERANGE Miron Berlin <mironatpro@hotmail.com>
2024-03-05 15:42 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox