File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -379,19 +379,23 @@ uint64_t kaitai::kstream::get_mask_ones(int n) {
379379// ========================================================================
380380
381381std::string kaitai::kstream::read_bytes (std::streamsize len) {
382- std::vector<char > result (len);
383-
384382 // NOTE: streamsize type is signed, negative values are only *supposed* to not be used.
385383 // http://en.cppreference.com/w/cpp/io/streamsize
386384 if (len < 0 ) {
387385 throw std::runtime_error (" read_bytes: requested a negative amount" );
388386 }
389-
390- if (len > 0 ) {
391- m_io->read (&result[0 ], len);
387+ else if (len == 0 ) {
388+ return std::string ();
389+ }
390+ else if (len > size ())
391+ {
392+ throw std::runtime_error (" read_bytes: requested length greater than stream size" );
392393 }
393394
394- return std::string (result.begin (), result.end ());
395+ std::string result (len, 0 );
396+ m_io->read (&result[0 ], len);
397+
398+ return result;
395399}
396400
397401std::string kaitai::kstream::read_bytes_full () {
You can’t perform that action at this time.
0 commit comments