From 15af706286212c933595ba8228d2d334fb81e0f7 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 26 Nov 2018 19:09:08 -0500 Subject: [PATCH] Fix crash due to cygwin bug in getline, bug1349. --- Changes | 2 ++ src/V3File.cpp | 12 ++++++------ src/V3Options.cpp | 7 +++---- src/V3Os.cpp | 15 +++++++++++++++ src/V3Os.h | 3 +++ src/VlcTop.cpp | 12 +++++------- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/Changes b/Changes index 02adbd6e7..e57aa65b2 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix hang on bad pattern keys, bug1364. [Matt Myers] +**** Fix crash due to cygwin bug in getline, bug1349. [Affe Mao] + * Verilator 4.006 2018-10-27 diff --git a/src/V3File.cpp b/src/V3File.cpp index 41c130002..d98b3ab36 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -206,12 +206,12 @@ inline bool V3FileDependImp::checkTimes(const string& filename, const string& cm return false; } { - string ignore; getline(*ifp, ignore); + string ignore = V3Os::getline(*ifp); } { - char chkDir; *ifp>>chkDir; - char quote; *ifp>>quote; - string chkCmdline; getline(*ifp, chkCmdline, '"'); + char chkDir; *ifp>>chkDir; + char quote; *ifp>>quote; + string chkCmdline = V3Os::getline(*ifp, '"'); string cmdline = stripQuotes(cmdlineIn); if (cmdline != chkCmdline) { UINFO(2," --check-times failed: different command line\n"); @@ -228,8 +228,8 @@ inline bool V3FileDependImp::checkTimes(const string& filename, const string& cm time_t chkCnstime; *ifp>>chkCnstime; time_t chkMstime; *ifp>>chkMstime; time_t chkMnstime; *ifp>>chkMnstime; - char quote; *ifp>>quote; - string chkFilename; getline(*ifp, chkFilename, '"'); + char quote; *ifp>>quote; + string chkFilename = V3Os::getline(*ifp, '"'); V3Options::fileNfsFlush(chkFilename); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 474243b2c..be2bbcfbf 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -1113,10 +1113,9 @@ void V3Options::parseOptsFile(FileLine* fl, const string& filename, bool rel) { string whole_file; bool inCmt = false; while (!ifp->eof()) { - string line; - getline(*ifp, line); - // Strip simple comments - string oline; + string line = V3Os::getline(*ifp); + // Strip simple comments + string oline; // cppcheck-suppress StlMissingComparison for (string::const_iterator pos = line.begin(); pos != line.end(); ++pos) { if (inCmt) { diff --git a/src/V3Os.cpp b/src/V3Os.cpp index 482269ba9..cf43c2147 100644 --- a/src/V3Os.cpp +++ b/src/V3Os.cpp @@ -165,6 +165,21 @@ bool V3Os::filenameIsRel(const string& filename) { return (filename.length()>0 && filename[0] != '/'); } +//###################################################################### +// File utilities + +string V3Os::getline(std::istream& is, char delim) { + string line; +#if defined(__CYGWIN__) // Work around buggy implementation of getline + char buf[65536]; + is.getline(buf, 65535, delim); + line = buf; +#else + std::getline(is, line, delim); +#endif + return line; +} + //###################################################################### // Directory utilities diff --git a/src/V3Os.h b/src/V3Os.h index ab6a62761..bc6ca9a70 100644 --- a/src/V3Os.h +++ b/src/V3Os.h @@ -46,6 +46,9 @@ public: static string filenameRealPath(const string& filename); ///< Return realpath of filename static bool filenameIsRel(const string& filename); ///< True if relative + // METHODS (file utilities) + static string getline(std::istream& is, char delim='\n'); + // METHODS (directory utilities) static void createDir(const string& dirname); static void unlinkRegexp(const string& dir, const string& regexp); diff --git a/src/VlcTop.cpp b/src/VlcTop.cpp index 84dc3e0b1..69f4632d3 100644 --- a/src/VlcTop.cpp +++ b/src/VlcTop.cpp @@ -42,10 +42,9 @@ void VlcTop::readCoverage(const string& filename, bool nonfatal) { VlcTest* testp = tests().newTest(filename, 0, 0); while (!is.eof()) { - string line; - getline(is, line); - //UINFO(9," got "<