1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-25 17:57:42 +03:00

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 <noel.power@suse.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Noel Power 2019-05-21 12:56:06 +01:00 committed by Noel Power
parent 5477b83db2
commit 02017d35f4

View File

@ -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) {