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) {
379
379
// ========================================================================
380
380
381
381
std::string kaitai::kstream::read_bytes (std::streamsize len) {
382
- std::vector<char > result (len);
383
-
384
382
// NOTE: streamsize type is signed, negative values are only *supposed* to not be used.
385
383
// http://en.cppreference.com/w/cpp/io/streamsize
386
384
if (len < 0 ) {
387
385
throw std::runtime_error (" read_bytes: requested a negative amount" );
388
386
}
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" );
392
393
}
393
394
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;
395
399
}
396
400
397
401
std::string kaitai::kstream::read_bytes_full () {
You can’t perform that action at this time.
0 commit comments