We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b4ae643 commit 26a9760Copy full SHA for 26a9760
common/util.cc
@@ -12,6 +12,7 @@
12
#include <iomanip>
13
#include <random>
14
#include <sstream>
15
+#include <limits>
16
17
#ifdef __linux__
18
#include <sys/prctl.h>
@@ -78,8 +79,9 @@ std::string read_file(const std::string& fn) {
78
79
std::ifstream f(fn, std::ios::binary | std::ios::in);
80
if (f.is_open()) {
81
f.seekg(0, std::ios::end);
- int size = f.tellg();
82
- if (f.good() && size > 0) {
+ std::streamsize size = f.tellg();
83
+ // seekg and tellg on a directory doesn't return pos_type(-1) but max(streamsize)
84
+ if (f.good() && size > 0 && size < std::numeric_limits<std::streamsize>::max()) {
85
std::string result(size, '\0');
86
f.seekg(0, std::ios::beg);
87
f.read(result.data(), size);
0 commit comments