preproc: Fix garbage at the end of #warning/#error lines at EOF

Using #warning or #error at the very end of a file would generate a
trailing garbage character in diagnostics, apparently caused by
read_rest_of_line() checking for EOF before the stream can actually know
it's at EOF.

I'm not good at streams, but this fixes the bug for me with no
regressions, and the function in question is only used by the
code handling #warning/#error anyway.
This commit is contained in:
Ignacio R. Morelle 2015-04-05 02:41:39 -03:00
parent 695026c7e6
commit db0a663858

View file

@ -734,7 +734,7 @@ std::string preprocessor_data::read_line()
std::string preprocessor_data::read_rest_of_line()
{
std::string res;
while(!in_.eof() && in_.peek() != '\n') {
while(in_.peek() != '\n' && !in_.eof()) {
int c = in_.get();
if (c != '\r')
res += static_cast<char>(c);