From 02017d35f43b69b988841b29bd68c5b440edb4e7 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Tue, 21 May 2019 12:56:06 +0100 Subject: [PATCH] s3/printing: cppcheck avoid 'nullPointerArithmetic:' error source3/printing/notify.c:94: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck] /home/samba/samba-pidl/source3/printing/notify.c:96: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck] /home/samba/samba-pidl/source3/printing/notify.c:103: error: nullPointerArithmetic: Pointer addition with NULL pointer. <--[cppcheck] flatten_message function depends on behaviour of tdb_pack which will return the bytes that would be written (without actually writing to the buffer) if the bufsize passed is <=0. What we need to avoid here is the default modification of buf (when it is initially NULL) Signed-off-by: Noel Power Reviewed-by: Andreas Schneider --- source3/printing/notify.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source3/printing/notify.c b/source3/printing/notify.c index d2c5f72fff5..56747272394 100644 --- a/source3/printing/notify.c +++ b/source3/printing/notify.c @@ -91,19 +91,23 @@ again: /* Pack header */ - len += tdb_pack(buf + len, buflen - len, "f", msg->printer); + len += tdb_pack(buf ? buf + len : NULL, + buf ? buflen - len : 0, "f", msg->printer); - len += tdb_pack(buf + len, buflen - len, "ddddddd", + len += tdb_pack(buf ? buf + len : NULL, + buf ? buflen - len : 0, "ddddddd", (uint32_t)q->tv.tv_sec, (uint32_t)q->tv.tv_usec, msg->type, msg->field, msg->id, msg->len, msg->flags); /* Pack data */ if (msg->len == 0) - len += tdb_pack(buf + len, buflen - len, "dd", + len += tdb_pack(buf ? buf + len : NULL, + buf ? buflen - len : 0, "dd", msg->notify.value[0], msg->notify.value[1]); else - len += tdb_pack(buf + len, buflen - len, "B", + len += tdb_pack(buf ? buf + len : NULL, + buf ? buflen - len : 0, "B", msg->len, msg->notify.data); if (buflen != len) {