From cfc79d91467e6fd3855c15e1194a3e0582eb7331 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Tue, 20 Jul 2021 21:00:53 +0300 Subject: [PATCH] Fix history file conversion if file is empty --- base/common/ReplxxLineReader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/common/ReplxxLineReader.cpp b/base/common/ReplxxLineReader.cpp index 9c65b1dfe4c..c79013f1850 100644 --- a/base/common/ReplxxLineReader.cpp +++ b/base/common/ReplxxLineReader.cpp @@ -69,7 +69,7 @@ void convertHistoryFile(const std::string & path, replxx::Replxx & rx) } std::string line; - if (!getline(in, line).good()) + if (getline(in, line).bad()) { rx.print("Cannot read from %s (for conversion): %s\n", path.c_str(), errnoToString(errno).c_str()); @@ -78,7 +78,7 @@ void convertHistoryFile(const std::string & path, replxx::Replxx & rx) /// This is the marker of the date, no need to convert. static char const REPLXX_TIMESTAMP_PATTERN[] = "### dddd-dd-dd dd:dd:dd.ddd"; - if (line.starts_with("### ") && line.size() == strlen(REPLXX_TIMESTAMP_PATTERN)) + if (line.empty() || (line.starts_with("### ") && line.size() == strlen(REPLXX_TIMESTAMP_PATTERN))) { return; }