From 9fc783f609240a5d529f937d9e4056c19c647db0 Mon Sep 17 00:00:00 2001 From: Anna Rift Date: Fri, 22 Nov 2024 10:23:58 -0800 Subject: [PATCH] Use std::getline to restore unlimited length driver strings Signed-off-by: Anna Rift --- compiler/util/files.cpp | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/compiler/util/files.cpp b/compiler/util/files.cpp index 4183614988d1..8a29dee561a3 100644 --- a/compiler/util/files.cpp +++ b/compiler/util/files.cpp @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -209,22 +210,11 @@ void restoreDriverTmp(const char* tmpFilePath, fileinfo* tmpFileDummy = openTmpFile(tmpFilePath, "a"); closefile(tmpFileDummy); - fileinfo* tmpFile = openTmpFile(tmpFilePath, "r"); - - char strBuf[4096]; - while (fgets(strBuf, sizeof(strBuf), tmpFile->fptr)) { - // Note: Using strlen here (instead of strnlen) is safe because fgets - // guarantees null termination. - size_t len = strlen(strBuf); - // remove trailing newline, which fgets preserves unless buffer is exceeded - assert(strBuf[len - 1] == '\n' && "stored line exceeds maximum length"); - strBuf[--len] = '\0'; - - // invoke restoring function - restoreSavedString(strBuf); + std::ifstream fileStream(genIntermediateFilename(tmpFilePath)); + std::string line; + while (std::getline(fileStream, line)) { + restoreSavedString(line.c_str()); } - - closefile(tmpFile); } void restoreDriverTmpMultiline(