obmc-console: Address bugprone-sizeof-expression
Disable the lint where we know the implementation is valid, but do not
disable it globally.
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: Ie1640d82138fe91a401188cf966250103a25dde6
diff --git a/console-server.c b/console-server.c
index 4521ef7..8e24da6 100644
--- a/console-server.c
+++ b/console-server.c
@@ -534,17 +534,22 @@
/* add one to our pollers array */
n = console->n_pollers++;
- console->pollers =
- realloc(console->pollers,
- sizeof(*console->pollers) * console->n_pollers);
+ /*
+ * We're managing an array of pointers to aggregates, so don't warn about sizeof() on a
+ * pointer type.
+ */
+ /* NOLINTBEGIN(bugprone-sizeof-expression) */
+ console->pollers = reallocarray(console->pollers, console->n_pollers,
+ sizeof(*console->pollers));
+ /* NOLINTEND(bugprone-sizeof-expression) */
console->pollers[n] = poller;
/* increase pollfds array too */
console->pollfds =
- realloc(console->pollfds,
- sizeof(*console->pollfds) *
- (MAX_INTERNAL_POLLFD + console->n_pollers));
+ reallocarray(console->pollfds,
+ (MAX_INTERNAL_POLLFD + console->n_pollers),
+ sizeof(*console->pollfds));
/* shift the end pollfds up by one */
memcpy(&console->pollfds[n + 1], &console->pollfds[n],
@@ -569,13 +574,19 @@
console->n_pollers--;
- /* remove the item from the pollers array... */
+ /*
+ * Remove the item from the pollers array...
+ *
+ * We're managing an array of pointers to aggregates, so don't warn about sizeof() on a
+ * pointer type.
+ */
+ /* NOLINTBEGIN(bugprone-sizeof-expression) */
memmove(&console->pollers[i], &console->pollers[i + 1],
sizeof(*console->pollers) * (console->n_pollers - i));
- console->pollers =
- realloc(console->pollers,
- sizeof(*console->pollers) * console->n_pollers);
+ console->pollers = reallocarray(console->pollers, console->n_pollers,
+ sizeof(*console->pollers));
+ /* NOLINTEND(bugprone-sizeof-expression) */
/* ... and the pollfds array */
memmove(&console->pollfds[i], &console->pollfds[i + 1],
@@ -583,9 +594,9 @@
(MAX_INTERNAL_POLLFD + console->n_pollers - i));
console->pollfds =
- realloc(console->pollfds,
- sizeof(*console->pollfds) *
- (MAX_INTERNAL_POLLFD + console->n_pollers));
+ reallocarray(console->pollfds,
+ (MAX_INTERNAL_POLLFD + console->n_pollers),
+ sizeof(*console->pollfds));
free(poller);
}
diff --git a/ringbuffer.c b/ringbuffer.c
index 48c163a..efa5204 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -77,8 +77,14 @@
rbc->pos = rb->tail;
n = rb->n_consumers++;
- rb->consumers = realloc(rb->consumers,
- sizeof(*rb->consumers) * rb->n_consumers);
+ /*
+ * We're managing an array of pointers to aggregates, so don't warn about sizeof() on a
+ * pointer type.
+ */
+ /* NOLINTBEGIN(bugprone-sizeof-expression) */
+ rb->consumers = reallocarray(rb->consumers, rb->n_consumers,
+ sizeof(*rb->consumers));
+ /* NOLINTEND(bugprone-sizeof-expression) */
rb->consumers[n] = rbc;
return rbc;
@@ -97,11 +103,17 @@
rb->n_consumers--;
+ /*
+ * We're managing an array of pointers to aggregates, so don't warn about sizeof() on a
+ * pointer type.
+ */
+ /* NOLINTBEGIN(bugprone-sizeof-expression) */
memmove(&rb->consumers[i], &rb->consumers[i + 1],
sizeof(*rb->consumers) * (rb->n_consumers - i));
- rb->consumers = realloc(rb->consumers,
- sizeof(*rb->consumers) * rb->n_consumers);
+ rb->consumers = reallocarray(rb->consumers, rb->n_consumers,
+ sizeof(*rb->consumers));
+ /* NOLINTEND(bugprone-sizeof-expression) */
free(rbc);
}
diff --git a/socket-handler.c b/socket-handler.c
index d7aaa67..954c326 100644
--- a/socket-handler.c
+++ b/socket-handler.c
@@ -86,10 +86,16 @@
client = NULL;
sh->n_clients--;
+ /*
+ * We're managing an array of pointers to aggregates, so don't warn about sizeof() on a
+ * pointer type.
+ */
+ /* NOLINTBEGIN(bugprone-sizeof-expression) */
memmove(&sh->clients[idx], &sh->clients[idx + 1],
sizeof(*sh->clients) * (sh->n_clients - idx));
sh->clients =
- realloc(sh->clients, sizeof(*sh->clients) * sh->n_clients);
+ reallocarray(sh->clients, sh->n_clients, sizeof(*sh->clients));
+ /* NOLINTEND(bugprone-sizeof-expression) */
}
static void client_set_blocked(struct client *client, bool blocked)
@@ -299,8 +305,14 @@
sh->console, client_ringbuffer_poll, client);
n = sh->n_clients++;
+ /*
+ * We're managing an array of pointers to aggregates, so don't warn about sizeof() on a
+ * pointer type.
+ */
+ /* NOLINTBEGIN(bugprone-sizeof-expression) */
sh->clients =
- realloc(sh->clients, sizeof(*sh->clients) * sh->n_clients);
+ reallocarray(sh->clients, sh->n_clients, sizeof(*sh->clients));
+ /* NOLINTEND(bugprone-sizeof-expression) */
sh->clients[n] = client;
return POLLER_OK;