]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1603] fix kea-lfc ignoring lines without newline
authorAndrei Pavel <andrei@isc.org>
Fri, 11 Dec 2020 10:03:55 +0000 (12:03 +0200)
committerAndrei Pavel <andrei@isc.org>
Mon, 4 Jan 2021 17:43:53 +0000 (17:43 +0000)
src/lib/util/csv_file.cc

index 1fa54c0da60b3ddbfc1f294dce1b08069aafbfdf..86cc6d0be8935b6fc9d3022d1679cb9118b43a72 100644 (file)
@@ -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.