| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> |
| Cc: | Tristan Partin <tristan(at)partin(dot)io>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, malis(at)pgrust(dot)com |
| Subject: | Re: Fix a host of strto*() bugs |
| Date: | 2026-08-05 08:15:18 |
| Message-ID: | anLxFuckyDaM0juH@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, Aug 04, 2026 at 05:14:43PM +0200, Alvaro Herrera wrote:
> I'm thinking something like
> uint64 pg_strtouint64(const char *s, char **endptr, uint32 options, error_callback cb);
>
> where we parse and return the number, and in case of any failure, we
> call the error callback which can do an ereport() or pg_fatal() or
> whatever. So the caller need only set up a callback, and then all calls
> to the conversion function can be straightforward and not concern
> themselves with the platform specific errno handling.
>
> We can use the options bitmask to mediate any potential caller-specific
> needs, for example
> INTEGER_CONV_OCTAL
> INTEGER_CONV_HEX
> to override the default assumption of base 10.
I am not sure that we would need to diverge from the existing "base"
argument, passing down an option which is an equivalent of it feels
kind of confusing to me.
While looking at all the callers of strtou64() and strtoi64(), I can't
help but notice that each call has its own assumptions in terms of
endptr handling, minus the range checks they may or may not do. An
error callback may be adapted if some of the range checks are fixed,
but some of them rely on a parse state (parse_manifest.c). With all
that in mind, I am not entirely convinced that this would lead to an
overall simplification, quite the opposite actually. The new pg_()
routine could be given a context pointer that is passed down as an
argument of the error_callback, still that doesn't stick well here..
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Akshay Joshi | 2026-08-05 08:21:52 | Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements |
| Previous Message | Vitaly Davydov | 2026-08-05 08:10:34 | Re: Deadlock detector fails to activate on a hot standby replica |