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

Commit6a640d1

Browse files
committed
Add missing null terminator to escaped string; clean up unnecessarily
obscurantist coding conventions.
1 parent0c657ba commit6a640d1

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.58 2004/10/0717:29:12 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.59 2004/10/0718:57:26 tgl Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -181,7 +181,7 @@ static void vacuum_db(void);
181181
staticvoidmake_template0(void);
182182
staticvoidtrapsig(intsignum);
183183
staticvoidcheck_ok(void);
184-
staticvoidescape_locale(char**locale);
184+
staticchar*escape_quotes(constchar*src);
185185
staticboolchklocale(constchar*locale);
186186
staticvoidsetlocales(void);
187187
staticvoidusage(constchar*progname);
@@ -1100,20 +1100,19 @@ setup_config(void)
11001100
snprintf(repltok,sizeof(repltok),"shared_buffers = %d",n_buffers);
11011101
conflines=replace_token(conflines,"#shared_buffers = 1000",repltok);
11021102

1103-
1104-
escape_locale(&lc_messages);
1103+
lc_messages=escape_quotes(lc_messages);
11051104
snprintf(repltok,sizeof(repltok),"lc_messages = '%s'",lc_messages);
11061105
conflines=replace_token(conflines,"#lc_messages = 'C'",repltok);
11071106

1108-
escape_locale(&lc_monetary);
1107+
lc_monetary=escape_quotes(lc_monetary);
11091108
snprintf(repltok,sizeof(repltok),"lc_monetary = '%s'",lc_monetary);
11101109
conflines=replace_token(conflines,"#lc_monetary = 'C'",repltok);
11111110

1112-
escape_locale(&lc_numeric);
1111+
lc_numeric=escape_quotes(lc_numeric);
11131112
snprintf(repltok,sizeof(repltok),"lc_numeric = '%s'",lc_numeric);
11141113
conflines=replace_token(conflines,"#lc_numeric = 'C'",repltok);
11151114

1116-
escape_locale(&lc_time);
1115+
lc_time=escape_quotes(lc_time);
11171116
snprintf(repltok,sizeof(repltok),"lc_time = '%s'",lc_time);
11181117
conflines=replace_token(conflines,"#lc_time = 'C'",repltok);
11191118

@@ -1902,22 +1901,23 @@ check_ok()
19021901
}
19031902

19041903
/*
1905-
* Escape any single quotes or backslashes inlocale
1904+
* Escape any single quotes or backslashes ingiven string
19061905
*/
1907-
staticvoid
1908-
escape_locale(char**locale)
1906+
staticchar*
1907+
escape_quotes(constchar*src)
19091908
{
1910-
intlen=strlen(*locale),
1909+
intlen=strlen(src),
19111910
i,j;
1912-
char*loc_temp=xmalloc(len*2+1);
1911+
char*result=xmalloc(len*2+1);
19131912

19141913
for (i=0,j=0;i<len;i++)
19151914
{
1916-
if ((*locale)[i]=='\''||(*locale)[i]=='\\')
1917-
loc_temp[j++]='\\';
1918-
loc_temp[j++]=(*locale)[i];
1915+
if (src[i]=='\''||src[i]=='\\')
1916+
result[j++]='\\';
1917+
result[j++]=src[i];
19191918
}
1920-
*locale=loc_temp;
1919+
result[j]='\0';
1920+
returnresult;
19211921
}
19221922

19231923
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp