1010 *
1111 *
1212 * IDENTIFICATION
13- * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.133 2004/10/12 21 :54:38 petere Exp $
13+ * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.134 2004/11/17 19 :54:24 tgl Exp $
1414 *
1515 *-------------------------------------------------------------------------
1616 */
@@ -218,6 +218,7 @@ next_token_expand(FILE *file)
218218char * comma_str = pstrdup ("" );
219219bool trailing_comma ;
220220char * incbuf ;
221+ int needed ;
221222
222223do
223224{
@@ -239,16 +240,14 @@ next_token_expand(FILE *file)
239240else
240241incbuf = pstrdup (buf );
241242
242- comma_str = repalloc (comma_str ,
243- strlen (comma_str )+ strlen (incbuf )+ 1 );
243+ needed = strlen (comma_str )+ strlen (incbuf )+ 1 ;
244+ if (trailing_comma )
245+ needed ++ ;
246+ comma_str = repalloc (comma_str ,needed );
244247strcat (comma_str ,incbuf );
245- pfree (incbuf );
246-
247248if (trailing_comma )
248- {
249- comma_str = repalloc (comma_str ,strlen (comma_str )+ 1 + 1 );
250249strcat (comma_str ,MULTI_VALUE_SEP );
251- }
250+ pfree ( incbuf );
252251}while (trailing_comma );
253252
254253return comma_str ;
@@ -327,29 +326,31 @@ tokenize_inc_file(const char *inc_filename)
327326pfree (inc_fullname );
328327
329328/* return empty string, it matches nothing */
330- return pstrdup ( "" ) ;
329+ return comma_str ;
331330}
332331pfree (inc_fullname );
333332
334333/* There is possible recursion here if the file contains @ */
335334tokenize_file (inc_file ,& inc_lines ,& inc_line_nums );
336335FreeFile (inc_file );
337336
338- /* Create comma-separate string from List */
337+ /* Create comma-separated string from List */
339338foreach (line ,inc_lines )
340339{
341340List * token_list = (List * )lfirst (line );
342341ListCell * token ;
343342
344343foreach (token ,token_list )
345344{
346- if (strlen (comma_str ))
347- {
348- comma_str = repalloc (comma_str ,strlen (comma_str )+ 1 );
345+ int oldlen = strlen (comma_str );
346+ int needed ;
347+
348+ needed = oldlen + strlen (lfirst (token ))+ 1 ;
349+ if (oldlen > 0 )
350+ needed ++ ;
351+ comma_str = repalloc (comma_str ,needed );
352+ if (oldlen > 0 )
349353strcat (comma_str ,MULTI_VALUE_SEP );
350- }
351- comma_str = repalloc (comma_str ,
352- strlen (comma_str )+ strlen (lfirst (token ))+ 1 );
353354strcat (comma_str ,lfirst (token ));
354355}
355356}