Hi.
https://git.postgresql.org/cgit/postgresql.git/commit/?id=213a1b89527049cb27bbcd6871fdb0c0916b43e1
+Datum
+statatt_build_stavalues(const char *staname, FmgrInfo *array_in,
Datum d, Oid typid,
+ int32 typmod, bool *ok)
+{
+ LOCAL_FCINFO(fcinfo, 8);
+ char *s;
+ Datum result;
+ ErrorSaveContext escontext = {T_ErrorSaveContext};
+
+ escontext.details_wanted = true;
+
+ s = TextDatumGetCString(d);
+
+ InitFunctionCallInfoData(*fcinfo, array_in, 3, InvalidOid,
+ (Node *) &escontext, NULL);
+
+ fcinfo->args[0].value = CStringGetDatum(s);
+ fcinfo->args[0].isnull = false;
+ fcinfo->args[1].value = ObjectIdGetDatum(typid);
+ fcinfo->args[1].isnull = false;
+ fcinfo->args[2].value = Int32GetDatum(typmod);
+ fcinfo->args[2].isnull = false;
+
+ result = FunctionCallInvoke(fcinfo);
+
+ pfree(s);
+
+ if (escontext.error_occurred)
+ {
+ escontext.error_data->elevel = WARNING;
+ ThrowErrorData(escontext.error_data);
+ *ok = false;
+ return (Datum) 0;
+ }
The above LOCAL_FCINFO(fcinfo, 8);
should be
LOCAL_FCINFO(fcinfo, 3);
That mistake is harmless now, but if somebody use
LOCAL_FCINFO(fcinfo, 1), then it may have potential problems.
So let's try to use InputFunctionCallSafe instead, see attached.
I found this while trying to use InputFunctionCallSafe inside array_in_safe.
Should we consider fully refactoring array_in_safe to use it too?
From b60af0fa8e1a8cb9139cdc884bc5e625a2bb1ee7 Mon Sep 17 00:00:00 2001
From: jian he <[email protected]>
Date: Sat, 27 Jun 2026 13:13:22 +0800
Subject: [PATCH v1 1/1] use InputFunctionCallSafe when possible
---
src/backend/statistics/stat_utils.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/src/backend/statistics/stat_utils.c b/src/backend/statistics/stat_utils.c
index a673e3c704..05710e6b6b 100644
--- a/src/backend/statistics/stat_utils.c
+++ b/src/backend/statistics/stat_utils.c
@@ -569,7 +569,6 @@ Datum
statatt_build_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid typid,
int32 typmod, bool *ok)
{
- LOCAL_FCINFO(fcinfo, 8);
char *s;
Datum result;
ErrorSaveContext escontext = {T_ErrorSaveContext};
@@ -578,21 +577,8 @@ statatt_build_stavalues(const char *staname, FmgrInfo *array_in, Datum d, Oid ty
s = TextDatumGetCString(d);
- InitFunctionCallInfoData(*fcinfo, array_in, 3, InvalidOid,
- (Node *) &escontext, NULL);
-
- fcinfo->args[0].value = CStringGetDatum(s);
- fcinfo->args[0].isnull = false;
- fcinfo->args[1].value = ObjectIdGetDatum(typid);
- fcinfo->args[1].isnull = false;
- fcinfo->args[2].value = Int32GetDatum(typmod);
- fcinfo->args[2].isnull = false;
-
- result = FunctionCallInvoke(fcinfo);
-
- pfree(s);
-
- if (escontext.error_occurred)
+ if (!InputFunctionCallSafe(array_in, s, typid, typmod,
+ (Node *) &escontext, &result))
{
escontext.error_data->elevel = WARNING;
ThrowErrorData(escontext.error_data);
--
2.34.1