From: Andrei Pavel Date: Fri, 11 Dec 2020 10:03:55 +0000 (+0200) Subject: [#1603] fix kea-lfc ignoring lines without newline X-Git-Tag: Kea-1.9.4~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38cbc69b555a71d5965cfd2ea4361cc2351d09ae;p=thirdparty%2Fkea.git [#1603] fix kea-lfc ignoring lines without newline --- diff --git a/src/lib/util/csv_file.cc b/src/lib/util/csv_file.cc index 1fa54c0da6..86cc6d0be8 100644 --- a/src/lib/util/csv_file.cc +++ b/src/lib/util/csv_file.cc @@ -272,20 +272,24 @@ CSVFile::next(CSVRow& row, const bool skip_validation) { // Get exactly one line of the file. std::string line; std::getline(*fs_, line); - // If we got empty line because we reached the end of file - // return an empty row. - if (line.empty() && fs_->eof()) { - row = EMPTY_ROW(); - return (true); - } else if (!fs_->good()) { - // If we hit an IO error, communicate it to the caller but do NOT close - // the stream. Caller may try again. - setReadMsg("error reading a row from CSV file '" - + std::string(filename_) + "'"); - return (false); + // If we didn't read anything... + if (line.empty()) { + // If we reached the end of file, return an empty row to signal EOF. + if (fs_->eof()) { + row = EMPTY_ROW(); + return (true); + + } else if (!fs_->good()) { + // If we hit an IO error, communicate it to the caller but do NOT close + // the stream. Caller may try again. + setReadMsg("error reading a row from CSV file '" + + std::string(filename_) + "'"); + return (false); + } } - // If we read anything, parse it. + + // Parse the line. row.parse(line); // And check if it is correct.