Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8e67380

Browse files
committed
Remove useless empty string initializations
This coding style probably stems from the days of shell scripts.Reviewed-by: Aleksandr Parfenov <a.parfenov@postgrespro.ru>
1 parent9361bc3 commit8e67380

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,29 @@ static const char *const auth_methods_local[] = {
118118
staticchar*share_path=NULL;
119119

120120
/* values to be obtained from arguments */
121-
staticchar*pg_data="";
122-
staticchar*encoding="";
123-
staticchar*locale="";
124-
staticchar*lc_collate="";
125-
staticchar*lc_ctype="";
126-
staticchar*lc_monetary="";
127-
staticchar*lc_numeric="";
128-
staticchar*lc_time="";
129-
staticchar*lc_messages="";
130-
staticconstchar*default_text_search_config="";
131-
staticchar*username="";
121+
staticchar*pg_data=NULL;
122+
staticchar*encoding=NULL;
123+
staticchar*locale=NULL;
124+
staticchar*lc_collate=NULL;
125+
staticchar*lc_ctype=NULL;
126+
staticchar*lc_monetary=NULL;
127+
staticchar*lc_numeric=NULL;
128+
staticchar*lc_time=NULL;
129+
staticchar*lc_messages=NULL;
130+
staticconstchar*default_text_search_config=NULL;
131+
staticchar*username=NULL;
132132
staticboolpwprompt= false;
133133
staticchar*pwfilename=NULL;
134134
staticchar*superuser_password=NULL;
135-
staticconstchar*authmethodhost="";
136-
staticconstchar*authmethodlocal="";
135+
staticconstchar*authmethodhost=NULL;
136+
staticconstchar*authmethodlocal=NULL;
137137
staticbooldebug= false;
138138
staticboolnoclean= false;
139139
staticbooldo_sync= true;
140140
staticboolsync_only= false;
141141
staticboolshow_setting= false;
142142
staticbooldata_checksums= false;
143-
staticchar*xlog_dir="";
143+
staticchar*xlog_dir=NULL;
144144

145145

146146
/* internal vars */
@@ -1285,17 +1285,13 @@ bootstrap_template1(void)
12851285
{
12861286
PG_CMD_DECL;
12871287
char**line;
1288-
char*talkargs="";
12891288
char**bki_lines;
12901289
charheaderline[MAXPGPATH];
12911290
charbuf[64];
12921291

12931292
printf(_("running bootstrap script ... "));
12941293
fflush(stdout);
12951294

1296-
if (debug)
1297-
talkargs="-d 5";
1298-
12991295
bki_lines=readfile(bki_file);
13001296

13011297
/* Check that bki file appears to be of the right version */
@@ -1359,7 +1355,9 @@ bootstrap_template1(void)
13591355
"\"%s\" --boot -x1 %s %s %s",
13601356
backend_exec,
13611357
data_checksums ?"-k" :"",
1362-
boot_options,talkargs);
1358+
boot_options,
1359+
debug ?"-d 5" :"");
1360+
13631361

13641362
PG_CMD_OPEN;
13651363

@@ -2136,6 +2134,10 @@ check_locale_name(int category, const char *locale, char **canonname)
21362134
/* save may be pointing at a modifiable scratch variable, so copy it. */
21372135
save=pg_strdup(save);
21382136

2137+
/* for setlocale() call */
2138+
if (!locale)
2139+
locale="";
2140+
21392141
/* set the locale with setlocale, to see if it accepts it. */
21402142
res=setlocale(category,locale);
21412143

@@ -2223,19 +2225,19 @@ setlocales(void)
22232225

22242226
/* set empty lc_* values to locale config if set */
22252227

2226-
if (strlen(locale)>0)
2228+
if (locale)
22272229
{
2228-
if (strlen(lc_ctype)==0)
2230+
if (!lc_ctype)
22292231
lc_ctype=locale;
2230-
if (strlen(lc_collate)==0)
2232+
if (!lc_collate)
22312233
lc_collate=locale;
2232-
if (strlen(lc_numeric)==0)
2234+
if (!lc_numeric)
22332235
lc_numeric=locale;
2234-
if (strlen(lc_time)==0)
2236+
if (!lc_time)
22352237
lc_time=locale;
2236-
if (strlen(lc_monetary)==0)
2238+
if (!lc_monetary)
22372239
lc_monetary=locale;
2238-
if (strlen(lc_messages)==0)
2240+
if (!lc_messages)
22392241
lc_messages=locale;
22402242
}
22412243

@@ -2310,7 +2312,7 @@ usage(const char *progname)
23102312
staticvoid
23112313
check_authmethod_unspecified(constchar**authmethod)
23122314
{
2313-
if (*authmethod==NULL||strlen(*authmethod)==0)
2315+
if (*authmethod==NULL)
23142316
{
23152317
authwarning=_("\nWARNING: enabling \"trust\" authentication for local connections\n"
23162318
"You can change this by editing pg_hba.conf or using the option -A, or\n"
@@ -2367,7 +2369,7 @@ setup_pgdata(void)
23672369
char*pgdata_get_env,
23682370
*pgdata_set_env;
23692371

2370-
if (strlen(pg_data)==0)
2372+
if (!pg_data)
23712373
{
23722374
pgdata_get_env=getenv("PGDATA");
23732375
if (pgdata_get_env&&strlen(pgdata_get_env))
@@ -2479,7 +2481,7 @@ setup_locale_encoding(void)
24792481
lc_time);
24802482
}
24812483

2482-
if (strlen(encoding)==0)
2484+
if (!encoding)
24832485
{
24842486
intctype_enc;
24852487

@@ -2589,10 +2591,10 @@ setup_data_file_paths(void)
25892591
void
25902592
setup_text_search(void)
25912593
{
2592-
if (strlen(default_text_search_config)==0)
2594+
if (!default_text_search_config)
25932595
{
25942596
default_text_search_config=find_matching_ts_config(lc_ctype);
2595-
if (default_text_search_config==NULL)
2597+
if (!default_text_search_config)
25962598
{
25972599
printf(_("%s: could not find suitable text search configuration for locale \"%s\"\n"),
25982600
progname,lc_ctype);
@@ -2728,7 +2730,7 @@ create_xlog_or_symlink(void)
27282730
/* form name of the place for the subdirectory or symlink */
27292731
subdirloc=psprintf("%s/pg_wal",pg_data);
27302732

2731-
if (strcmp(xlog_dir,"")!=0)
2733+
if (xlog_dir)
27322734
{
27332735
intret;
27342736

@@ -3131,7 +3133,7 @@ main(int argc, char *argv[])
31313133
* Non-option argument specifies data directory as long as it wasn't
31323134
* already specified with -D / --pgdata
31333135
*/
3134-
if (optind<argc&&strlen(pg_data)==0)
3136+
if (optind<argc&&!pg_data)
31353137
{
31363138
pg_data=pg_strdup(argv[optind]);
31373139
optind++;
@@ -3187,7 +3189,7 @@ main(int argc, char *argv[])
31873189
setup_bin_paths(argv[0]);
31883190

31893191
effective_user=get_id();
3190-
if (strlen(username)==0)
3192+
if (!username)
31913193
username=effective_user;
31923194

31933195
if (strncmp(username,"pg_",3)==0)

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ typedef enum
7676
/* Global options */
7777
staticchar*basedir=NULL;
7878
staticTablespaceListtablespace_dirs= {NULL,NULL};
79-
staticchar*xlog_dir="";
79+
staticchar*xlog_dir=NULL;
8080
staticcharformat='p';/* p(lain)/t(ar) */
8181
staticchar*label="pg_basebackup base backup";
8282
staticboolnoclean= false;
@@ -2347,7 +2347,7 @@ main(int argc, char **argv)
23472347
temp_replication_slot= false;
23482348
}
23492349

2350-
if (strcmp(xlog_dir,"")!=0)
2350+
if (xlog_dir)
23512351
{
23522352
if (format!='p')
23532353
{
@@ -2398,7 +2398,7 @@ main(int argc, char **argv)
23982398
}
23992399

24002400
/* Create pg_wal symlink, if required */
2401-
if (strcmp(xlog_dir,"")!=0)
2401+
if (xlog_dir)
24022402
{
24032403
char*linkloc;
24042404

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp