Be more careful about newline-chomping in pgbench.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Sep 2017 21:25:31 +0000 (17:25 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Sep 2017 21:25:31 +0000 (17:25 -0400)
commit0b707d6ea75971fb464a74e7a6334e2d5ae822b7
treeeb11bc5bfd79f20f2807de83d918b8f8904f1e9b
parentc23bb6badfa2048d17c08ebcfd81adf942292e51
Be more careful about newline-chomping in pgbench.

process_backslash_command would drop the last character of the input
command on the assumption that it was a newline.  Given a non newline
terminated input file, this could result in dropping the last character
of the command.  Fix that by doing an actual test that we're removing
a newline.

While at it, allow for Windows newlines (\r\n), and suppress multiple
newlines if any.  I do not think either of those cases really occur,
since (a) we read script files in text mode and (b) the lexer stops
when it hits a newline.  But it's cheap enough and it provides a
stronger guarantee about what the result string looks like.

This is just cosmetic, I think, since the possibly-overly-chomped
line was only used for display not for further processing.  So
it doesn't seem necessary to back-patch.

Fabien Coelho, reviewed by Nikolay Shaplov, whacked around a bit by me

Discussion: https://postgr.es/m/alpine.DEB.2.20.1704171422500.4025@lancre
src/bin/pgbench/exprscan.l
src/bin/pgbench/pgbench.c
src/bin/pgbench/pgbench.h