From 05b9d3393cb5a326365fccc57808b6a3968b028f Mon Sep 17 00:00:00 2001
From: alterego655 <824662526@qq.com>
Date: Mon, 10 Nov 2025 18:03:00 +0800
Subject: [PATCH v2] injection_points: Report actual character limits in error
 messages

Previously, error messages for oversized injection point names, libraries,
and functions showed buffer sizes (64, 128, 128) instead of the usable
character limits (63, 127, 127). This could confuse users, since repeat('a', 64)
failed with "maximum of 64" when the real limit was 63 characters.

Update the messages to report (buffer_size - 1) and use the word
"characters" for clarity. Also change "bytes" for the private data limit
to distinguish it from string limits.

New messages now state:
- "maximum of 63 characters" for names
- "maximum of 127 characters" for libraries and functions
- "maximum of 1023 bytes" for private data
---
 src/backend/utils/misc/injection_point.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/backend/utils/misc/injection_point.c b/src/backend/utils/misc/injection_point.c
index 83b887b6978..f244c4a7983 100644
--- a/src/backend/utils/misc/injection_point.c
+++ b/src/backend/utils/misc/injection_point.c
@@ -283,17 +283,17 @@ InjectionPointAttach(const char *name,
 	int			free_idx;
 
 	if (strlen(name) >= INJ_NAME_MAXLEN)
-		elog(ERROR, "injection point name %s too long (maximum of %u)",
-			 name, INJ_NAME_MAXLEN);
+		elog(ERROR, "injection point name %s too long (maximum of %u characters)",
+			 name, INJ_NAME_MAXLEN - 1);
 	if (strlen(library) >= INJ_LIB_MAXLEN)
-		elog(ERROR, "injection point library %s too long (maximum of %u)",
-			 library, INJ_LIB_MAXLEN);
+		elog(ERROR, "injection point library %s too long (maximum of %u characters)",
+			 library, INJ_LIB_MAXLEN - 1);
 	if (strlen(function) >= INJ_FUNC_MAXLEN)
-		elog(ERROR, "injection point function %s too long (maximum of %u)",
-			 function, INJ_FUNC_MAXLEN);
+		elog(ERROR, "injection point function %s too long (maximum of %u characters)",
+			 function, INJ_FUNC_MAXLEN - 1);
 	if (private_data_size >= INJ_PRIVATE_MAXLEN)
-		elog(ERROR, "injection point data too long (maximum of %u)",
-			 INJ_PRIVATE_MAXLEN);
+		elog(ERROR, "injection point data too long (maximum of %u bytes)",
+			 INJ_PRIVATE_MAXLEN - 1);
 
 	/*
 	 * Allocate and register a new injection point.  A new point should not
-- 
2.51.0

