use argument instead of global variable

From: Junwang Zhao <zhjwpku(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: use argument instead of global variable
Date: 2022-08-10 15:50:50
Message-ID: CAEG8a3+ACNH3-iKi388O4_MtWM3fKiMXGhpHj-Ak1pcLZf1jKg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The caller of `get_stats_option_name` pass optarg as the argument,
it's saner to use the argument instead of the global variable set
by getopt, which is more safe since the argument has a *const*
specifier.

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 11e802eba9..68552b8779 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3598,9 +3598,9 @@ get_stats_option_name(const char *arg)
switch (arg[0])
{
case 'p':
- if (optarg[1] == 'a') /* "parser" */
+ if (arg[1] == 'a') /* "parser" */
return "log_parser_stats";
- else if (optarg[1] == 'l') /* "planner"
*/
+ else if (arg[1] == 'l') /* "planner" */
return "log_planner_stats";
break;

--
Regards
Junwang Zhao

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-10 16:20:47 Re: moving basebackup code to its own directory
Previous Message Andrew Dunstan 2022-08-10 15:50:42 Re: SQL/JSON features for v15