From 8419d4577641e519a49883cc80360bc348db2825 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 27 Feb 2018 19:16:47 +0100 Subject: [PATCH] coccinelle: similar to reallocarray() let's also systematically use malloc_multiply() --- coccinelle/malloc_multiply.cocci | 20 ++++++++++++++++++++ src/udev/udev-rules.c | 2 +- src/vconsole/vconsole-setup.c | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 coccinelle/malloc_multiply.cocci diff --git a/coccinelle/malloc_multiply.cocci b/coccinelle/malloc_multiply.cocci new file mode 100644 index 0000000000..3284edf737 --- /dev/null +++ b/coccinelle/malloc_multiply.cocci @@ -0,0 +1,20 @@ +@@ +expression q, n, m; +@@ +- q = malloc((n)*(m)) ++ q = malloc_multiply(n, m) +@@ +expression q, n, m; +@@ +- q = malloc(n*(m)) ++ q = malloc_multiply(n, m) +@@ +expression q, n, m; +@@ +- q = malloc((n)*m) ++ q = malloc_multiply(n, m) +@@ +expression q, n, m; +@@ +- q = malloc(n*m) ++ q = malloc_multiply(n, m) diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 3b0ddb5118..635811c59f 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1544,7 +1544,7 @@ struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) { udev_list_init(udev, &file_list, true); /* init token array and string buffer */ - rules->tokens = malloc(PREALLOC_TOKEN * sizeof(struct token)); + rules->tokens = malloc_multiply(PREALLOC_TOKEN, sizeof(struct token)); if (rules->tokens == NULL) return udev_rules_unref(rules); rules->token_max = PREALLOC_TOKEN; diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 2e0e09d843..a9cc2bf63c 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -248,7 +248,7 @@ static void setup_remaining_vcs(int src_fd, unsigned src_idx, bool utf8) { * requries 32 per glyph, regardless of the actual height - see the comment above #define * max_font_size 65536 in drivers/tty/vt/vt.c for more details. */ - fontbuf = malloc((cfo.width + 7) / 8 * 32 * cfo.charcount); + fontbuf = malloc_multiply((cfo.width + 7) / 8 * 32, cfo.charcount); if (!fontbuf) { log_oom(); return;