]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: similar to reallocarray() let's also systematically use malloc_multiply() 8336/head
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Feb 2018 18:16:47 +0000 (19:16 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 2 Mar 2018 11:39:07 +0000 (12:39 +0100)
coccinelle/malloc_multiply.cocci [new file with mode: 0644]
src/udev/udev-rules.c
src/vconsole/vconsole-setup.c

diff --git a/coccinelle/malloc_multiply.cocci b/coccinelle/malloc_multiply.cocci
new file mode 100644 (file)
index 0000000..3284edf
--- /dev/null
@@ -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)
index 3b0ddb51184e6be1e9b73151e1fc8a271d9ee3bd..635811c59fd294a2cd29c144eab7de043d76a4ea 100644 (file)
@@ -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;
index 2e0e09d8434e4f07f2a06c10b6475defe29c4220..a9cc2bf63c1700ee309baceb21107694fcac6a5d 100644 (file)
@@ -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;