Skip to content

Commit

Permalink
binarybuffer: add asserts for the number of requested bits for get/se…
Browse files Browse the repository at this point in the history
…t functions

Change-Id: Ieca5b4e690c9713ad60dc9d8c223c2d64822e2f5
Signed-off-by: Parshintsev Anatoly <[email protected]>
Reviewed-on: https://review.openocd.org/c/openocd/+/8427
Tested-by: jenkins
Reviewed-by: Tomas Vanek <[email protected]>
Reviewed-by: Jan Matyas <[email protected]>
Reviewed-by: Antonio Borneo <[email protected]>
  • Loading branch information
aap-sc authored and borneoa committed Sep 15, 2024
1 parent 760dd1f commit e5a2001
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/helper/binarybuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
static inline void buf_set_u32(uint8_t *_buffer,
unsigned first, unsigned num, uint32_t value)
{
assert(num >= 1 && num <= 32);
uint8_t *buffer = _buffer;

if ((num == 32) && (first == 0)) {
Expand Down Expand Up @@ -64,6 +65,7 @@ static inline void buf_set_u32(uint8_t *_buffer,
static inline void buf_set_u64(uint8_t *_buffer,
unsigned first, unsigned num, uint64_t value)
{
assert(num >= 1 && num <= 64);
uint8_t *buffer = _buffer;

if ((num == 32) && (first == 0)) {
Expand Down Expand Up @@ -102,6 +104,7 @@ static inline void buf_set_u64(uint8_t *_buffer,
static inline uint32_t buf_get_u32(const uint8_t *_buffer,
unsigned first, unsigned num)
{
assert(num >= 1 && num <= 32);
const uint8_t *buffer = _buffer;

if ((num == 32) && (first == 0)) {
Expand Down Expand Up @@ -131,6 +134,7 @@ static inline uint32_t buf_get_u32(const uint8_t *_buffer,
static inline uint64_t buf_get_u64(const uint8_t *_buffer,
unsigned first, unsigned num)
{
assert(num >= 1 && num <= 64);
const uint8_t *buffer = _buffer;

if ((num == 32) && (first == 0)) {
Expand Down

0 comments on commit e5a2001

Please sign in to comment.