On Fri, Nov 22, 2024 at 2:49 AM Ales Musil <[email protected]> wrote:
>
> Add helper to truncate the buffer to certain size which might be
> useful if some earlier part of the buffer can be reused multiple
> times without copying the whole buffer.
>
> Signed-off-by: Ales Musil <[email protected]>
> ---
>  include/openvswitch/ofpbuf.h | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h
> index 1fc4a3a7f..bac574548 100644
> --- a/include/openvswitch/ofpbuf.h
> +++ b/include/openvswitch/ofpbuf.h
> @@ -292,6 +292,13 @@ static inline bool ofpbuf_oversized(const struct ofpbuf 
> *ofpacts)
>      return (char *)ofpbuf_tail(ofpacts) - (char *)ofpacts->header > 
> UINT16_MAX;
>  }
>

Hello Ales,

Especially given that it's not currently used in code, it would be
good to have a comment here explaining the use.

> +static inline void ofpbuf_truncate(struct ofpbuf *b, size_t size)
> +{
> +    ovs_assert(b->size >= size);
> +    b->data = (uint8_t *) b->data - size;


I may misunderstand this, but the function is supposed to be removing
bytes from the end of the buffer? Then why is b->data modified?

Cheers,
M

> +    b->size = b->size - size;
> +}
> +
>  #ifdef  __cplusplus
>  }
>  #endif
> --
> 2.47.0
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to