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

Commit340b66c

Browse files
committed
Cause fmtId to always use its internal buffer for the returned value,
in hopes of making erroneous usage more apparent. Per discussion 15-Apr.
1 parent1cf693a commit340b66c

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.44 2002/04/24 14:03:22 momjian Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.45 2002/05/06 17:34:45 tgl Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -2069,25 +2069,32 @@ _reconnectAsOwner(ArchiveHandle *AH, const char *dbname, TocEntry *te)
20692069
/*
20702070
* fmtId
20712071
*
2072-
*checks input stringfor non-lowercase characters
2073-
*returns pointer to input string or string surrounded by double quotes
2072+
*Quotes input stringif it's not a legitimate SQL identifier as-is,
2073+
*or all the time if force_quotes is true.
20742074
*
2075-
*Note that the returned string should be used immediately since it
2076-
*uses a static buffer to hold the string. Non-reentrant but faster?
2075+
*Note that the returned string must be used before calling fmtId again,
2076+
*since we re-use the same return buffer each time. Non-reentrant but
2077+
*avoids memory leakage.
20772078
*/
20782079
constchar*
20792080
fmtId(constchar*rawid,boolforce_quotes)
20802081
{
20812082
staticPQExpBufferid_return=NULL;
20822083
constchar*cp;
20832084

2085+
if (id_return)/* first time through? */
2086+
resetPQExpBuffer(id_return);
2087+
else
2088+
id_return=createPQExpBuffer();
2089+
20842090
if (!force_quotes)
20852091
{
20862092
/* do a quick check on the first character... */
2087-
if (!islower((unsignedchar)*rawid))
2093+
if (!islower((unsignedchar)*rawid)&&*rawid!='_')
20882094
force_quotes= true;
2089-
/* otherwise check the entire string */
20902095
else
2096+
{
2097+
/* otherwise check the entire string */
20912098
for (cp=rawid;*cp;cp++)
20922099
{
20932100
if (!(islower((unsignedchar)*cp)||
@@ -2098,32 +2105,30 @@ fmtId(const char *rawid, bool force_quotes)
20982105
break;
20992106
}
21002107
}
2108+
}
21012109
}
21022110

21032111
if (!force_quotes)
2104-
returnrawid;/* no quoting needed */
2105-
2106-
if(id_return)
2107-
resetPQExpBuffer(id_return);
2112+
{
2113+
/* no quoting needed */
2114+
appendPQExpBufferStr(id_return,rawid);
2115+
}
21082116
else
2109-
id_return=createPQExpBuffer();
2110-
2111-
appendPQExpBufferChar(id_return,'\"');
2112-
for (cp=rawid;*cp;cp++)
21132117
{
2114-
/*
2115-
* Did we find a double-quote in the string? Then make this a
2116-
* double double-quote per SQL99. Before, we put in a
2117-
* backslash/double-quote pair. - thomas 2000-08-05
2118-
*/
2119-
if (*cp=='\"')
2118+
appendPQExpBufferChar(id_return,'\"');
2119+
for (cp=rawid;*cp;cp++)
21202120
{
2121-
appendPQExpBufferChar(id_return,'\"');
2122-
appendPQExpBufferChar(id_return,'\"');
2121+
/*
2122+
* Did we find a double-quote in the string? Then make this a
2123+
* double double-quote per SQL99. Before, we put in a
2124+
* backslash/double-quote pair. - thomas 2000-08-05
2125+
*/
2126+
if (*cp=='\"')
2127+
appendPQExpBufferChar(id_return,'\"');
2128+
appendPQExpBufferChar(id_return,*cp);
21232129
}
2124-
appendPQExpBufferChar(id_return,*cp);
2130+
appendPQExpBufferChar(id_return,'\"');
21252131
}
2126-
appendPQExpBufferChar(id_return,'\"');
21272132

21282133
returnid_return->data;
21292134
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp