Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler driver bug reading long dependency paths #26310

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions compiler/util/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <unistd.h>

#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <cstdlib>
Expand Down Expand Up @@ -207,24 +208,14 @@ void restoreDriverTmp(const char* tmpFilePath,
// Create file iff it did not already exist, for simpler reading logic in the
// rest of the function.
fileinfo* tmpFileDummy = openTmpFile(tmpFilePath, "a");
const char* path = tmpFileDummy->pathname;
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(path);
std::string line;
while (std::getline(fileStream, line)) {
restoreSavedString(line.c_str());
}

closefile(tmpFile);
}

void restoreDriverTmpMultiline(
Expand Down
Loading