v8-0006-cleanup-avoid-local-variables-shadowed-by-globals.patch

application/octet-stream

Filename: v8-0006-cleanup-avoid-local-variables-shadowed-by-globals.patch
Type: application/octet-stream
Part: 5
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 v8-0006
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/include/common/controldata_utils.h 2 2
src/include/libpq/libpq.h 1 1
src/interfaces/ecpg/preproc/descriptor.c 17 17
src/interfaces/ecpg/preproc/preproc_extern.h 3 3
From 48745ffcc7f2e0c48a9a697f0bfba6cefc02d855 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 v8 06/12] 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/include/common/controldata_utils.h       |  4 +--
 src/include/libpq/libpq.h                    |  2 +-
 src/interfaces/ecpg/preproc/descriptor.c     | 34 ++++++++++----------
 src/interfaces/ecpg/preproc/preproc_extern.h |  6 ++--
 6 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/src/backend/libpq/be-secure-common.c b/src/backend/libpq/be-secure-common.c
index ad04bedaa1d..ee59b77c938 100644
--- a/src/backend/libpq/be-secure-common.c
+++ b/src/backend/libpq/be-secure-common.c
@@ -118,17 +118,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;
 	}
 
@@ -138,7 +138,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;
 	}
 
@@ -164,7 +164,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;
 	}
 
@@ -174,7 +174,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 4ab116afcde..4b4a35fc01c 100644
--- a/src/common/controldata_utils.c
+++ b/src/common/controldata_utils.c
@@ -50,11 +50,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);
 }
@@ -187,7 +187,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;
@@ -212,7 +212,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/include/common/controldata_utils.h b/src/include/common/controldata_utils.h
index 6dd0999f805..a9d52cd4410 100644
--- a/src/include/common/controldata_utils.h
+++ b/src/include/common/controldata_utils.h
@@ -12,10 +12,10 @@
 
 #include "catalog/pg_control.h"
 
-extern ControlFileData *get_controlfile(const char *DataDir, bool *crc_ok_p);
+extern ControlFileData *get_controlfile(const char *data_dir, bool *crc_ok_p);
 extern ControlFileData *get_controlfile_by_exact_path(const char *ControlFilePath,
 													  bool *crc_ok_p);
-extern void update_controlfile(const char *DataDir,
+extern void update_controlfile(const char *data_dir,
 							   ControlFileData *ControlFile, bool do_sync);
 
 #endif							/* COMMON_CONTROLDATA_UTILS_H */
diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
index c9b934d2321..a948e246078 100644
--- a/src/include/libpq/libpq.h
+++ b/src/include/libpq/libpq.h
@@ -162,7 +162,7 @@ enum ssl_protocol_versions
 extern int	run_ssl_passphrase_command(const char *cmd, const char *prompt,
 									   bool is_server_start,
 									   char *buf, int size);
-extern bool check_ssl_key_file_permissions(const char *ssl_key_file,
+extern bool check_ssl_key_file_permissions(const char *sslKeyFile,
 										   bool isServerStart);
 extern int	load_hosts(List **hosts, char **err_msg);
 
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;
diff --git a/src/interfaces/ecpg/preproc/preproc_extern.h b/src/interfaces/ecpg/preproc/preproc_extern.h
index 2c89e30621e..337b406380a 100644
--- a/src/interfaces/ecpg/preproc/preproc_extern.h
+++ b/src/interfaces/ecpg/preproc/preproc_extern.h
@@ -97,9 +97,9 @@ extern void output_set_descr(const char *desc_name, const char *index);
 extern void push_assignment(const char *var, enum ECPGdtype value);
 extern struct variable *find_variable(const char *name);
 extern void whenever_action(int mode);
-extern void add_descriptor(const char *name, const char *connection);
-extern void drop_descriptor(const char *name, const char *connection);
-extern struct descriptor *lookup_descriptor(const char *name, const char *connection);
+extern void add_descriptor(const char *name, const char *conn_str);
+extern void drop_descriptor(const char *name, const char *conn_str);
+extern struct descriptor *lookup_descriptor(const char *name, const char *conn_str);
 extern struct variable *descriptor_variable(const char *name, int input);
 extern struct variable *sqlda_variable(const char *name);
 extern void add_variable_to_head(struct arguments **list,
-- 
2.50.1 (Apple Git-155)