On 5/11/26 12:03, David Gibson wrote:
struct pool always needs a non-NULL buf field: it points either to the actual memory used to store packets, or for vhost-user to the vhost user memory structure which will contain the packets. We set this pointer when we initialise the pool. However, clang-tidy (as of 22.1.4, at least) doesn't realise this in packet_check_range(), causing UB warnings due to the subtraction of ptr and p->buf.
Clue it in with an assert().
Signed-off-by: David Gibson
Reviewed-by: Laurent Vivier
--- packet.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/packet.c b/packet.c index 1cb74b74..7a347be6 100644 --- a/packet.c +++ b/packet.c @@ -51,6 +51,8 @@ static int packet_check_range(const struct pool *p, const char *ptr, size_t len, { struct vdev_memory *memory;
+ assert(p->buf); + if (len > PACKET_MAX_LEN) { debug("packet range length %zu (max %zu), %s:%i", len, PACKET_MAX_LEN, func, line);