• Tom Lane's avatar
    Simplify some long-obsolete code in hba.c's next_token(). · 1e5a5d03
    Tom Lane authored
    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 e5e2fc84
    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 7f49a67f 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.
    1e5a5d03
hba.c 75.9 KB