Minor pg_amcheck fixes spotted while reading code

Started by Daniel Gustafssonover 4 years ago4 messages
#1Daniel Gustafsson
daniel@yesql.se
2 attachment(s)

When perusing the pg_amcheck code the other day for the recently pushed fixes I
found two small things that seem worth fixing: The help function progname
parameter shadows the global variable of the same name, which no doubt will
make static analyzers complain so we might as well fix that; and there is a
tiny typo in the test stanza.

Both fixed in the attached.

--
Daniel Gustafsson https://vmware.com/

Attachments:

0001-Fix-variable-shadowing.patchapplication/octet-stream; name=0001-Fix-variable-shadowing.patch; x-unix-mode=0644Download
From 91243ee427a910ac36e784b9001e4adc0ad6efa0 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Fri, 20 Aug 2021 14:08:46 +0200
Subject: [PATCH 1/2] Fix variable shadowing

The progname parameter shadows the global variable of the same name
which will cause static analyzers to complain.  Fix by renaming the
local variable.
---
 src/bin/pg_amcheck/pg_amcheck.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amcheck.c
index f4b1ef95e9..87c62a3b71 100644
--- a/src/bin/pg_amcheck/pg_amcheck.c
+++ b/src/bin/pg_amcheck/pg_amcheck.c
@@ -179,7 +179,7 @@ static void run_command(ParallelSlot *slot, const char *sql);
 static bool verify_heap_slot_handler(PGresult *res, PGconn *conn,
 									 void *context);
 static bool verify_btree_slot_handler(PGresult *res, PGconn *conn, void *context);
-static void help(const char *progname);
+static void help(const char *program_name);
 static void progress_report(uint64 relations_total, uint64 relations_checked,
 							uint64 relpages_total, uint64 relpages_checked,
 							const char *datname, bool force, bool finished);
@@ -1138,14 +1138,14 @@ verify_btree_slot_handler(PGresult *res, PGconn *conn, void *context)
  *
  * Prints help page for the program
  *
- * progname: the name of the executed program, such as "pg_amcheck"
+ * program_name: the name of the executed program, such as "pg_amcheck"
  */
 static void
-help(const char *progname)
+help(const char *program_name)
 {
-	printf(_("%s checks objects in a PostgreSQL database for corruption.\n\n"), progname);
+	printf(_("%s checks objects in a PostgreSQL database for corruption.\n\n"), program_name);
 	printf(_("Usage:\n"));
-	printf(_("  %s [OPTION]... [DBNAME]\n"), progname);
+	printf(_("  %s [OPTION]... [DBNAME]\n"), program_name);
 	printf(_("\nTarget options:\n"));
 	printf(_("  -a, --all                       check all databases\n"));
 	printf(_("  -d, --database=PATTERN          check matching database(s)\n"));
-- 
2.24.3 (Apple Git-128)

0002-pg_amcheck-test-typofix.patchapplication/octet-stream; name=0002-pg_amcheck-test-typofix.patch; x-unix-mode=0644Download
From 1ca4cb70710888e98c323b040f8b1640b92db0db Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Fri, 20 Aug 2021 15:22:44 +0200
Subject: [PATCH 2/2] pg_amcheck test typofix

---
 src/bin/pg_amcheck/t/002_nonesuch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/bin/pg_amcheck/t/002_nonesuch.pl b/src/bin/pg_amcheck/t/002_nonesuch.pl
index e30c1cc546..94bc5c2923 100644
--- a/src/bin/pg_amcheck/t/002_nonesuch.pl
+++ b/src/bin/pg_amcheck/t/002_nonesuch.pl
@@ -232,7 +232,7 @@ $node->command_checks_all(
 		qr/pg_amcheck: warning: no connectable databases to check matching "no_such_database\.public\.foo_idx"/,
 		qr/pg_amcheck: error: no relations to check/,
 	],
-	'checking otherwise existent objets in the wrong databases');
+	'checking otherwise existent objects in the wrong databases');
 
 
 #########################################
-- 
2.24.3 (Apple Git-128)

#2Mark Dilger
mark.dilger@enterprisedb.com
In reply to: Daniel Gustafsson (#1)
Re: Minor pg_amcheck fixes spotted while reading code

On Aug 20, 2021, at 11:19 AM, Daniel Gustafsson <daniel@yesql.se> wrote:

When perusing the pg_amcheck code the other day for the recently pushed fixes I
found two small things that seem worth fixing: The help function progname
parameter shadows the global variable of the same name, which no doubt will
make static analyzers complain so we might as well fix that; and there is a
tiny typo in the test stanza.

Both fixed in the attached.

--
Daniel Gustafsson https://vmware.com/

<0001-Fix-variable-shadowing.patch><0002-pg_amcheck-test-typofix.patch>

These look correct.


Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#3Michael Paquier
michael@paquier.xyz
In reply to: Mark Dilger (#2)
Re: Minor pg_amcheck fixes spotted while reading code

On Fri, Aug 20, 2021 at 11:42:09AM -0700, Mark Dilger wrote:

These look correct.

static void
-help(const char *progname)
+help(const char *program_name)
These were discussed not long ago, and I recall that they were in the
we-don't-care category. Note for example all the tools of
src/scripts/ and pg_dump/.
--
Michael

#4Daniel Gustafsson
daniel@yesql.se
In reply to: Michael Paquier (#3)
Re: Minor pg_amcheck fixes spotted while reading code

On 21 Aug 2021, at 02:43, Michael Paquier <michael@paquier.xyz> wrote:

On Fri, Aug 20, 2021 at 11:42:09AM -0700, Mark Dilger wrote:

These look correct.

static void
-help(const char *progname)
+help(const char *program_name)
These were discussed not long ago, and I recall that they were in the
we-don't-care category. Note for example all the tools of
src/scripts/ and pg_dump/.

Fair enough, I had missed that thread.

--
Daniel Gustafsson https://vmware.com/