Skip to content

Commit 27e504e

Browse files
vtjnashKristofferC
authored andcommitted
[coverage] fix length of coverage file (#34281)
Previously, we might append an extra empty line to the file. Also add error checking for I/O faults: > terminate called after throwing an instance of std::__ios_failure > what(): basic_ios::clear: iostream error Fixes JuliaCI/Coverage.jl#234
1 parent 897f048 commit 27e504e

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/codegen.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,15 +1831,21 @@ static void write_log_data(logdata_t &logData, const char *extension)
18311831
if (!isabspath(filename.c_str()))
18321832
filename = base + filename;
18331833
std::ifstream inf(filename.c_str());
1834-
if (inf.is_open()) {
1835-
std::string outfile = filename + extension;
1836-
std::ofstream outf(outfile.c_str(), std::ofstream::trunc | std::ofstream::out | std::ofstream::binary);
1834+
if (!inf.is_open())
1835+
continue;
1836+
std::string outfile = filename + extension;
1837+
std::ofstream outf(outfile.c_str(), std::ofstream::trunc | std::ofstream::out | std::ofstream::binary);
1838+
if (outf.is_open()) {
1839+
inf.exceptions(std::ifstream::badbit);
1840+
outf.exceptions(std::ifstream::failbit | std::ifstream::badbit);
18371841
char line[1024];
18381842
int l = 1;
18391843
unsigned block = 0;
18401844
while (!inf.eof()) {
18411845
inf.getline(line, sizeof(line));
1842-
if (inf.fail() && !inf.bad()) {
1846+
if (inf.fail()) {
1847+
if (inf.eof())
1848+
break; // no content on trailing line
18431849
// Read through lines longer than sizeof(line)
18441850
inf.clear();
18451851
inf.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
@@ -1862,8 +1868,8 @@ static void write_log_data(logdata_t &logData, const char *extension)
18621868
outf << " " << line << '\n';
18631869
}
18641870
outf.close();
1865-
inf.close();
18661871
}
1872+
inf.close();
18671873
}
18681874
}
18691875
}

0 commit comments

Comments
 (0)