Skip to content

Commit 6a640d1

Browse files
committed
Add missing null terminator to escaped string; clean up unnecessarily
obscurantist coding conventions.
1 parent 0c657ba commit 6a640d1

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/07 17:29:12 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.59 2004/10/07 18:57:26 tgl Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -181,7 +181,7 @@ static void vacuum_db(void);
181181
static void make_template0(void);
182182
static void trapsig(int signum);
183183
static void check_ok(void);
184-
static void escape_locale(char **locale);
184+
static char *escape_quotes(const char *src);
185185
static bool chklocale(const char *locale);
186186
static void setlocales(void);
187187
static void usage(const char *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 in locale
1904+
* Escape any single quotes or backslashes in given string
19061905
*/
1907-
static void
1908-
escape_locale(char **locale)
1906+
static char *
1907+
escape_quotes(const char *src)
19091908
{
1910-
int len = strlen(*locale),
1909+
int len = 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+
return result;
19211921
}
19221922

19231923
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy