sd-bus: add assert_cc for message allocation size

Use CONST_ALIGN_TO to express the compile-time overflow check for
the ALIGN(sizeof(sd_bus_message)) + sizeof(BusMessageHeader)
allocation, since ALIGN() is not constexpr.

CID#1548031

Follow-up for de1c301ed1
This commit is contained in:
Luca Boccassi
2026-03-28 21:41:02 +00:00
parent aa2cc18c76
commit 4f5b28b72c

View File

@@ -464,6 +464,8 @@ _public_ int sd_bus_message_new(
/* Creation of messages with _SD_BUS_MESSAGE_TYPE_INVALID is allowed. */
assert_return(type < _SD_BUS_MESSAGE_TYPE_MAX, -EINVAL);
/* Silence static analyzers */
assert_cc(sizeof(sd_bus_message) + sizeof(void*) + sizeof(BusMessageHeader) <= SIZE_MAX);
sd_bus_message *t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(BusMessageHeader));
if (!t)
return -ENOMEM;