From f38bf2bef09e52ba1e15678f5688132f282b50c2 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 12 Oct 2015 22:10:42 +0200 Subject: [PATCH] Be less verbose on overflow. --- bmusb.cpp | 12 ++++++++++-- bmusb.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bmusb.cpp b/bmusb.cpp index 6867805..ac02852 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -93,6 +93,9 @@ FrameAllocator::Frame MallocFrameAllocator::alloc_frame() void MallocFrameAllocator::release_frame(Frame frame) { + if (frame.overflow > 0) { + printf("%d bytes overflow after last (malloc) frame\n", int(frame.overflow)); + } unique_lock lock(freelist_mutex); freelist.push(unique_ptr(frame.data)); } @@ -263,8 +266,13 @@ void add_to_frame(FrameAllocator::Frame *current_frame, const char *frame_type_n int bytes = end - start; if (current_frame->len + bytes > current_frame->size) { - printf("%d bytes overflow after last %s frame\n", - int(current_frame->len + bytes - current_frame->size), frame_type_name); + current_frame->overflow = current_frame->len + bytes - current_frame->size; + current_frame->len = current_frame->size; + if (current_frame->overflow > 1048576) { + printf("%d bytes overflow after last %s frame\n", + int(current_frame->overflow), frame_type_name); + current_frame->overflow = 0; + } //dump_frame(); } else { if (current_frame->interleaved) { diff --git a/bmusb.h b/bmusb.h index 96a2257..b2725ab 100644 --- a/bmusb.h +++ b/bmusb.h @@ -25,6 +25,7 @@ class FrameAllocator { uint8_t *data2 = nullptr; // Only if interleaved == true. size_t len = 0; // Number of bytes we actually have. size_t size = 0; // Number of bytes we have room for. + size_t overflow = 0; void *userdata = nullptr; FrameAllocator *owner = nullptr; -- 2.39.2