From e35f0e4baa0cbcca9a969fc371ec5601152050bc Mon Sep 17 00:00:00 2001
From: zhanghu <kongbaik228@gmail.com>
Date: Fri, 27 Feb 2026 14:39:37 +0800
Subject: [PATCH v2 1/2] guc: Clarify dereference order in newval string checks

In check_backtrace_functions(), most accesses to the input string use
the form:

    (*newval)[i]

However, the empty-string check was written as:

    *newval[0] == '\0'

Since [] has higher precedence than *, this is parsed as
*(newval[0]). Although it produces the same result when the index
is zero, it implies array-style access on newval and is inconsistent
with the surrounding style.

Similarly, in check_archive_directory(), the empty-string check
was written as:

    *newval[0] == '\0'

In both cases, newval is a pointer-to-pointer used as an output
parameter in the GUC framework rather than a two-dimensional
character array. Rewriting these checks as:

    (*newval)[0] == '\0'

makes the intended dereference order explicit.

No functional change.

Author: zhanghu <kongbaik228@gmail.com>
---
 contrib/basic_archive/basic_archive.c | 2 +-
 src/backend/utils/error/elog.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/contrib/basic_archive/basic_archive.c b/contrib/basic_archive/basic_archive.c
index 6c7f985d48b..6860e4642ee 100644
--- a/contrib/basic_archive/basic_archive.c
+++ b/contrib/basic_archive/basic_archive.c
@@ -102,7 +102,7 @@ check_archive_directory(char **newval, void **extra, GucSource source)
 	 * Our check_configured callback also checks for this and prevents
 	 * archiving from proceeding if it is still empty.
 	 */
-	if (*newval == NULL || *newval[0] == '\0')
+	if (*newval == NULL || (*newval)[0] == '\0')
 		return true;
 
 	/*
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 0d0bf0f6aa5..650a79b7e12 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -2627,7 +2627,7 @@ check_backtrace_functions(char **newval, void **extra, GucSource source)
 		return false;
 	}
 
-	if (*newval[0] == '\0')
+	if ((*newval)[0] == '\0')
 	{
 		*extra = NULL;
 		return true;
-- 
2.33.0

