Ticket #3507: boost-regex-fread-return-check-r56576.patch

File boost-regex-fread-return-check-r56576.patch, 1.1 KB (added by mloskot <mateusz@…>, 13 years ago)

Patch with fread and fseek return value checks in regex library

  • libs/regex/src/fileiter.cpp

     
    258258            *p = 0;
    259259            *(reinterpret_cast<int*>(*node)) = 1;
    260260         }
    261          std::fseek(hfile, (node - _first) * buf_size, SEEK_SET);
    262          if(node == _last - 1)
    263             std::fread(*node + sizeof(int), _size % buf_size, 1, hfile);
     261
     262         std::size_t read_size = 0;
     263         int read_pos = std::fseek(hfile, (node - _first) * buf_size, SEEK_SET);
     264
     265         if(0 == read_pos && node == _last - 1)
     266            read_size = std::fread(*node + sizeof(int), _size % buf_size, 1, hfile);
    264267         else
    265             std::fread(*node + sizeof(int), buf_size, 1, hfile);
     268            read_size = std::fread(*node + sizeof(int), buf_size, 1, hfile);
     269
     270#ifndef BOOST_NO_EXCEPTIONS
     271         if (std::ferror(hfile))
     272         {
     273            throw std::runtime_error("Unable to read file.");
     274         }
     275#else
     276         BOOST_REGEX_NOEH_ASSERT(0 == std::ferror(hfile));
     277#endif
    266278      }
    267279      else
    268280      {