[COMMITTERS] pgsql: Simplify some long-obsolete code in hba.c's next_token(). - Mailing list pgsql-committers

From Tom Lane
Subject [COMMITTERS] pgsql: Simplify some long-obsolete code in hba.c's next_token().
Date
Msg-id E1cYLax-00066X-5e@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Simplify some long-obsolete code in hba.c's next_token().

next_token() oddly set its buffer space consumption limit to one before
the last char position in the buffer, not the last as you'd expect.
The reason is there was once an ugly kluge to mark keywords by appending
a newline to them, potentially requiring one more byte.  Commit e5e2fc842
removed that kluge, but failed to notice that the length limit could be
increased.

Also, remove some vestigial handling of newline characters in the buffer.
That was left over from when this function read the file directly using
getc().  Commit 7f49a67f9 changed it to read from a buffer, from which
tokenize_file had already removed the only possible occurrence of newline,
but did not simplify this function in consequence.

Also, ensure that we don't return with *lineptr set to someplace past the
terminating '\0'; that would be catastrophic if a caller were to ask for
another token from the same line.  This is just latent since no callers
actually do call again after a "false" return; but considering that it was
actually costing us extra code to do it wrong, we might as well make it
bulletproof.

Noted while reviewing pg_hba_file_rules patch.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/1e5a5d03da14ba9b734c6a2a1a822dcd8af110eb

Modified Files
--------------
src/backend/libpq/hba.c | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: [COMMITTERS] pgsql: Invent pg_hba_file_rules view to show the content ofpg_hba.conf
Next
From: Stephen Frost
Date:
Subject: [COMMITTERS] pgsql: test_pg_dump: perltidy cleanup