Fix bb bytes overrun issue

includes coverity fixes