*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.116.2.3 2004/09/18 01:23:12 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.116.2.4 2004/11/17 19:54:34 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char *comma_str = pstrdup("");
bool trailing_comma;
char *incbuf;
+ int needed;
do
{
else
incbuf = pstrdup(buf);
- comma_str = repalloc(comma_str,
- strlen(comma_str) + strlen(incbuf) + 1);
+ needed = strlen(comma_str) + strlen(incbuf) + 1;
+ if (trailing_comma)
+ needed++;
+ comma_str = repalloc(comma_str, needed);
strcat(comma_str, incbuf);
- pfree(incbuf);
-
if (trailing_comma)
- {
- comma_str = repalloc(comma_str, strlen(comma_str) + 1 + 1);
strcat(comma_str, MULTI_VALUE_SEP);
- }
+ pfree(incbuf);
} while (trailing_comma);
return comma_str;
pfree(inc_fullname);
/* return empty string, it matches nothing */
- return pstrdup("");
+ return comma_str;
}
pfree(inc_fullname);
inc_lines = tokenize_file(inc_file);
FreeFile(inc_file);
- /* Create comma-separate string from List */
+ /* Create comma-separated string from List */
foreach(line, inc_lines)
{
List *ln = lfirst(line);
/* First entry is line number */
foreach(token, lnext(ln))
{
- if (strlen(comma_str))
- {
- comma_str = repalloc(comma_str, strlen(comma_str) + 1);
+ int oldlen = strlen(comma_str);
+ int needed;
+
+ needed = oldlen + strlen(lfirst(token)) + 1;
+ if (oldlen > 0)
+ needed++;
+ comma_str = repalloc(comma_str, needed);
+ if (oldlen > 0)
strcat(comma_str, MULTI_VALUE_SEP);
- }
- comma_str = repalloc(comma_str,
- strlen(comma_str) + strlen(lfirst(token)) + 1);
strcat(comma_str, lfirst(token));
}
}