diff options
author | Benoît Ganne <bganne@cisco.com> | 2021-07-20 16:51:39 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2021-08-20 11:24:52 +0000 |
commit | 42e2140dd97c0d03c7edc033119e1e1bb59ed5a5 (patch) | |
tree | c3aadf7ffe7eb36797a43b93d9318b66d640e008 | |
parent | 1a19552eee24e447e6087de43a2eeb9250b8cae7 (diff) |
vppinfra: fix clib_random_buffer_get_data caching
When using cached bytes:
- do not overflow
- do not return the same bytes twice
Type: fix
Change-Id: I2a87b47a79300e56a2201b8fc3cb6cb15b592e28
Signed-off-by: Benoît Ganne <bganne@cisco.com>
-rw-r--r-- | src/vppinfra/random_buffer.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/vppinfra/random_buffer.h b/src/vppinfra/random_buffer.h index 320394d1862..dded53163fc 100644 --- a/src/vppinfra/random_buffer.h +++ b/src/vppinfra/random_buffer.h @@ -88,7 +88,7 @@ clib_random_buffer_get_data (clib_random_buffer_t * b, uword n_bytes) if (n_bytes <= l) { b->n_cached_bytes = l - n_bytes; - return &b->cached_bytes[l]; + return &b->cached_bytes[l - n_bytes]; } n_words = n_bytes / sizeof (uword); @@ -106,7 +106,7 @@ clib_random_buffer_get_data (clib_random_buffer_t * b, uword n_bytes) { b->cached_word = b->buffer[i]; b->n_cached_bytes = sizeof (uword) - n_bytes; - return b->cached_bytes; + return &b->cached_bytes[sizeof (uword) - n_bytes]; } else return b->buffer + i; |