File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#include " simdjson/jsonioutil.h"
22#include < cstdlib>
33#include < cstring>
4+ #include < climits>
45
56namespace simdjson {
67char *allocate_padded_buffer (size_t length) {
@@ -16,8 +17,16 @@ char *allocate_padded_buffer(size_t length) {
1617padded_string get_corpus (const std::string &filename) {
1718 std::FILE *fp = std::fopen (filename.c_str (), " rb" );
1819 if (fp != nullptr ) {
19- std::fseek (fp, 0 , SEEK_END );
20- size_t len = std::ftell (fp);
20+ if (std::fseek (fp, 0 , SEEK_END ) < 0 ) {
21+ std::fclose (fp);
22+ throw std::runtime_error (" cannot seek in the file" );
23+ }
24+ long llen = std::ftell (fp);
25+ if ((llen < 0 ) || (llen == LONG_MAX )) {
26+ std::fclose (fp);
27+ throw std::runtime_error (" cannot tell where we are in the file" );
28+ }
29+ size_t len = (size_t ) llen;
2130 padded_string s (len);
2231 if (s.data () == nullptr ) {
2332 std::fclose (fp);
You can’t perform that action at this time.
0 commit comments