From d5384f9e391a10177fd7bf06c866e62834f52896 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 15 Sep 2026 08:43:09 +0200 Subject: [PATCH v2 5/8] Change float{4,8}in_internal take const char * input argument This makes the function signature match strtof()/strtod(). A caller then doesn't have to cast away a const anymore. --- contrib/postgres_fdw/postgres_fdw.c | 2 +- src/backend/utils/adt/float.c | 32 ++++++++++++++--------------- src/include/utils/float.h | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index eceee1b649d..ec291d95fdc 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -6458,7 +6458,7 @@ set_float_arg(NullableDatum *arg, const char *s) { if (s) { - float4 val = float4in_internal((char *) s, NULL, "float", s, NULL); + float4 val = float4in_internal(s, NULL, "float", s, NULL); arg->value = Float4GetDatum(val); arg->isnull = false; diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c index fd7a6587132..18b43c81d74 100644 --- a/src/backend/utils/adt/float.c +++ b/src/backend/utils/adt/float.c @@ -221,7 +221,7 @@ float4in(PG_FUNCTION_ARGS) * comments also apply here, except regarding use in geometric types. */ float4 -float4in_internal(char *num, char **endptr_p, +float4in_internal(const char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext) { @@ -269,37 +269,37 @@ float4in_internal(char *num, char **endptr_p, if (pg_strncasecmp(num, "NaN", 3) == 0) { val = get_float4_nan(); - endptr = num + 3; + endptr = unconstify(char *, num) + 3; } else if (pg_strncasecmp(num, "Infinity", 8) == 0) { val = get_float4_infinity(); - endptr = num + 8; + endptr = unconstify(char *, num) + 8; } else if (pg_strncasecmp(num, "+Infinity", 9) == 0) { val = get_float4_infinity(); - endptr = num + 9; + endptr = unconstify(char *, num) + 9; } else if (pg_strncasecmp(num, "-Infinity", 9) == 0) { val = -get_float4_infinity(); - endptr = num + 9; + endptr = unconstify(char *, num) + 9; } else if (pg_strncasecmp(num, "inf", 3) == 0) { val = get_float4_infinity(); - endptr = num + 3; + endptr = unconstify(char *, num) + 3; } else if (pg_strncasecmp(num, "+inf", 4) == 0) { val = get_float4_infinity(); - endptr = num + 4; + endptr = unconstify(char *, num) + 4; } else if (pg_strncasecmp(num, "-inf", 4) == 0) { val = -get_float4_infinity(); - endptr = num + 4; + endptr = unconstify(char *, num) + 4; } else if (save_errno == ERANGE) { @@ -433,7 +433,7 @@ float8in(PG_FUNCTION_ARGS) * unreasonable amount of extra casting both here and in callers, so we don't. */ float8 -float8in_internal(char *num, char **endptr_p, +float8in_internal(const char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext) { @@ -475,37 +475,37 @@ float8in_internal(char *num, char **endptr_p, if (pg_strncasecmp(num, "NaN", 3) == 0) { val = get_float8_nan(); - endptr = num + 3; + endptr = unconstify(char *, num) + 3; } else if (pg_strncasecmp(num, "Infinity", 8) == 0) { val = get_float8_infinity(); - endptr = num + 8; + endptr = unconstify(char *, num) + 8; } else if (pg_strncasecmp(num, "+Infinity", 9) == 0) { val = get_float8_infinity(); - endptr = num + 9; + endptr = unconstify(char *, num) + 9; } else if (pg_strncasecmp(num, "-Infinity", 9) == 0) { val = -get_float8_infinity(); - endptr = num + 9; + endptr = unconstify(char *, num) + 9; } else if (pg_strncasecmp(num, "inf", 3) == 0) { val = get_float8_infinity(); - endptr = num + 3; + endptr = unconstify(char *, num) + 3; } else if (pg_strncasecmp(num, "+inf", 4) == 0) { val = get_float8_infinity(); - endptr = num + 4; + endptr = unconstify(char *, num) + 4; } else if (pg_strncasecmp(num, "-inf", 4) == 0) { val = -get_float8_infinity(); - endptr = num + 4; + endptr = unconstify(char *, num) + 4; } else if (save_errno == ERANGE) { diff --git a/src/include/utils/float.h b/src/include/utils/float.h index ffa743d6273..dbfbb3bf6ad 100644 --- a/src/include/utils/float.h +++ b/src/include/utils/float.h @@ -37,10 +37,10 @@ extern float8 float_overflow_error_ext(struct Node *escontext); extern float8 float_underflow_error_ext(struct Node *escontext); extern float8 float_zero_divide_error_ext(struct Node *escontext); extern int is_infinite(float8 val); -extern float8 float8in_internal(char *num, char **endptr_p, +extern float8 float8in_internal(const char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext); -extern float4 float4in_internal(char *num, char **endptr_p, +extern float4 float4in_internal(const char *num, char **endptr_p, const char *type_name, const char *orig_string, struct Node *escontext); extern char *float8out_internal(float8 num); -- 2.55.0