Skip to content

Commit 282570e

Browse files
committed
fix(encodingcheck): not crash when filesize is zero
1 parent 5ec7c19 commit 282570e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

.github/workflows/encodingcheck/encodingcheck.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ constexpr void print(std::format_string<Args...> fmt, Args&&... args)
2525
template<class... Args>
2626
constexpr void printerr(std::format_string<Args...> fmt, Args&&... args)
2727
{
28+
fflush(stderr);
2829
std::fputs(std::format(fmt, std::forward<decltype(args)>(args)...).c_str(), stderr);
30+
fflush(stderr);
2931
}
3032

3133
namespace fs = std::filesystem;
@@ -41,6 +43,10 @@ bool checkutf8(fs::path file)
4143
close(fd);
4244
throw fs::filesystem_error("fstat()", std::error_code{errno, std::system_category()});
4345
}
46+
if (statbuf.st_size == 0) {
47+
close(fd);
48+
return true;
49+
}
4450
auto ptr = static_cast<char*>(mmap(nullptr, statbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0));
4551
if (ptr == MAP_FAILED) {
4652
throw fs::filesystem_error("mmap()", std::error_code{errno, std::system_category()});
@@ -92,6 +98,7 @@ int main()
9298
catch(const std::exception& err){
9399
printerr("ERROR {} ({})\n", entry.path().c_str(), mime);
94100
printerr("{}", err.what());
101+
throw err;
95102
}
96103
}
97104

0 commit comments

Comments
 (0)