add some bounds checking asserts

custom
jacqueline 2 years ago
parent 7a54ff0df9
commit 25c5896dc5
  1. 6
      src/audio/include/stream_info.hpp

@ -67,6 +67,7 @@ class InputStream {
explicit InputStream(RawStream* s) : raw_(s) {} explicit InputStream(RawStream* s) : raw_(s) {}
void consume(std::size_t bytes) const { void consume(std::size_t bytes) const {
assert(raw_->info->bytes_in_stream >= bytes);
auto new_data = raw_->data.subspan(bytes); auto new_data = raw_->data.subspan(bytes);
std::move(new_data.begin(), new_data.end(), raw_->data.begin()); std::move(new_data.begin(), new_data.end(), raw_->data.begin());
raw_->info->bytes_in_stream = new_data.size_bytes(); raw_->info->bytes_in_stream = new_data.size_bytes();
@ -88,7 +89,10 @@ class OutputStream {
public: public:
explicit OutputStream(RawStream* s) : raw_(s) {} explicit OutputStream(RawStream* s) : raw_(s) {}
void add(std::size_t bytes) const { raw_->info->bytes_in_stream += bytes; } void add(std::size_t bytes) const {
assert(raw_->info->bytes_in_stream + bytes <= raw_->data.size_bytes());
raw_->info->bytes_in_stream += bytes;
}
bool prepare(const StreamInfo::Format& new_format) { bool prepare(const StreamInfo::Format& new_format) {
if (std::holds_alternative<std::monostate>(raw_->info->format)) { if (std::holds_alternative<std::monostate>(raw_->info->format)) {

Loading…
Cancel
Save