v6-0009-cleanup-avoid-local-variables-shadowed-by-globals.patch

application/octet-stream

Filename: v6-0009-cleanup-avoid-local-variables-shadowed-by-globals.patch
Type: application/octet-stream
Part: 8
Message: Re: Cleanup shadows variable warnings, round 1

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v6-0009
Subject: cleanup: avoid local variables shadowed by globals across several files
File+
src/backend/libpq/be-secure-common.c 6 6
src/common/controldata_utils.c 4 4
src/interfaces/ecpg/preproc/descriptor.c 17 17
From d4bca5957094705c8e9b55d59a33b49b46b65fec Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Tue, 2 Dec 2025 15:05:05 +0800
Subject: [PATCH v6 09/13] cleanup: avoid local variables shadowed by globals
 across several files

This commit fixes multiple instances where local variables used the same
names as global identifiers in various modules. The affected locals are
renamed so they are no longer shadowed by the globals and remain clear
within their respective scopes.

Author: Chao Li <lic@highgo.com>
Discussion: https://postgr.es/m/CAEoWx2kQ2x5gMaj8tHLJ3=jfC+p5YXHkJyHrDTiQw2nn2FJTmQ@mail.gmail.com
---
 src/backend/libpq/be-secure-common.c     | 12 ++++-----
 src/common/controldata_utils.c           |  8 +++---
 src/interfaces/ecpg/preproc/descriptor.c | 34 ++++++++++++------------
 3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/src/backend/libpq/be-secure-common.c b/src/backend/libpq/be-secure-common.c
index c074556dbfc..a9409ad3783 100644
--- a/src/backend/libpq/be-secure-common.c
+++ b/src/backend/libpq/be-secure-common.c
@@ -111,17 +111,17 @@ error:
  * Check permissions for SSL key files.
  */
 bool
-check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
+check_ssl_key_file_permissions(const char *sslKeyFile, bool isServerStart)
 {
 	int			loglevel = isServerStart ? FATAL : LOG;
 	struct stat buf;
 
-	if (stat(ssl_key_file, &buf) != 0)
+	if (stat(sslKeyFile, &buf) != 0)
 	{
 		ereport(loglevel,
 				(errcode_for_file_access(),
 				 errmsg("could not access private key file \"%s\": %m",
-						ssl_key_file)));
+						sslKeyFile)));
 		return false;
 	}
 
@@ -131,7 +131,7 @@ check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
 		ereport(loglevel,
 				(errcode(ERRCODE_CONFIG_FILE_ERROR),
 				 errmsg("private key file \"%s\" is not a regular file",
-						ssl_key_file)));
+						sslKeyFile)));
 		return false;
 	}
 
@@ -157,7 +157,7 @@ check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
 		ereport(loglevel,
 				(errcode(ERRCODE_CONFIG_FILE_ERROR),
 				 errmsg("private key file \"%s\" must be owned by the database user or root",
-						ssl_key_file)));
+						sslKeyFile)));
 		return false;
 	}
 
@@ -167,7 +167,7 @@ check_ssl_key_file_permissions(const char *ssl_key_file, bool isServerStart)
 		ereport(loglevel,
 				(errcode(ERRCODE_CONFIG_FILE_ERROR),
 				 errmsg("private key file \"%s\" has group or world access",
-						ssl_key_file),
+						sslKeyFile),
 				 errdetail("File must have permissions u=rw (0600) or less if owned by the database user, or permissions u=rw,g=r (0640) or less if owned by root.")));
 		return false;
 	}
diff --git a/src/common/controldata_utils.c b/src/common/controldata_utils.c
index 14530c6489a..b50bc04ef5a 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -49,11 +49,11 @@
  * file data is correct.
  */
 ControlFileData *
-get_controlfile(const char *DataDir, bool *crc_ok_p)
+get_controlfile(const char *data_dir, bool *crc_ok_p)
 {
 	char		ControlFilePath[MAXPGPATH];
 
-	snprintf(ControlFilePath, MAXPGPATH, "%s/%s", DataDir, XLOG_CONTROL_FILE);
+	snprintf(ControlFilePath, MAXPGPATH, "%s/%s", data_dir, XLOG_CONTROL_FILE);
 
 	return get_controlfile_by_exact_path(ControlFilePath, crc_ok_p);
 }
@@ -186,7 +186,7 @@ retry:
  * routine in the backend.
  */
 void
-update_controlfile(const char *DataDir,
+update_controlfile(const char *data_dir,
 				   ControlFileData *ControlFile, bool do_sync)
 {
 	int			fd;
@@ -211,7 +211,7 @@ update_controlfile(const char *DataDir,
 	memset(buffer, 0, PG_CONTROL_FILE_SIZE);
 	memcpy(buffer, ControlFile, sizeof(ControlFileData));
 
-	snprintf(ControlFilePath, sizeof(ControlFilePath), "%s/%s", DataDir, XLOG_CONTROL_FILE);
+	snprintf(ControlFilePath, sizeof(ControlFilePath), "%s/%s", data_dir, XLOG_CONTROL_FILE);
 
 #ifndef FRONTEND
 
diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c
index e8c7016bdc1..9dac761e393 100644
--- a/src/interfaces/ecpg/preproc/descriptor.c
+++ b/src/interfaces/ecpg/preproc/descriptor.c
@@ -72,7 +72,7 @@ ECPGnumeric_lvalue(char *name)
 static struct descriptor *descriptors;
 
 void
-add_descriptor(const char *name, const char *connection)
+add_descriptor(const char *name, const char *conn_str)
 {
 	struct descriptor *new;
 
@@ -83,15 +83,15 @@ add_descriptor(const char *name, const char *connection)
 
 	new->next = descriptors;
 	new->name = mm_strdup(name);
-	if (connection)
-		new->connection = mm_strdup(connection);
+	if (conn_str)
+		new->connection = mm_strdup(conn_str);
 	else
 		new->connection = NULL;
 	descriptors = new;
 }
 
 void
-drop_descriptor(const char *name, const char *connection)
+drop_descriptor(const char *name, const char *conn_str)
 {
 	struct descriptor *i;
 	struct descriptor **lastptr = &descriptors;
@@ -103,9 +103,9 @@ drop_descriptor(const char *name, const char *connection)
 	{
 		if (strcmp(name, i->name) == 0)
 		{
-			if ((!connection && !i->connection)
-				|| (connection && i->connection
-					&& strcmp(connection, i->connection) == 0))
+			if ((!conn_str && !i->connection)
+				|| (conn_str && i->connection
+					&& strcmp(conn_str, i->connection) == 0))
 			{
 				*lastptr = i->next;
 				free(i->connection);
@@ -115,14 +115,14 @@ drop_descriptor(const char *name, const char *connection)
 			}
 		}
 	}
-	if (connection)
-		mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
+	if (conn_str)
+		mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, conn_str);
 	else
 		mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
 }
 
 struct descriptor *
-lookup_descriptor(const char *name, const char *connection)
+lookup_descriptor(const char *name, const char *conn_str)
 {
 	struct descriptor *i;
 
@@ -133,20 +133,20 @@ lookup_descriptor(const char *name, const char *connection)
 	{
 		if (strcmp(name, i->name) == 0)
 		{
-			if ((!connection && !i->connection)
-				|| (connection && i->connection
-					&& strcmp(connection, i->connection) == 0))
+			if ((!conn_str && !i->connection)
+				|| (conn_str && i->connection
+					&& strcmp(conn_str, i->connection) == 0))
 				return i;
-			if (connection && !i->connection)
+			if (conn_str && !i->connection)
 			{
 				/* overwrite descriptor's connection */
-				i->connection = mm_strdup(connection);
+				i->connection = mm_strdup(conn_str);
 				return i;
 			}
 		}
 	}
-	if (connection)
-		mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, connection);
+	if (conn_str)
+		mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to connection %s does not exist", name, conn_str);
 	else
 		mmerror(PARSE_ERROR, ET_WARNING, "descriptor %s bound to the default connection does not exist", name);
 	return NULL;
-- 
2.50.1 (Apple Git-155)