]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coccinelle: automatically rewrite memset() to zero() or memzero() where we can
authorLennart Poettering <lennart@poettering.net>
Thu, 14 Dec 2017 18:47:46 +0000 (19:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 14 Dec 2017 18:47:46 +0000 (19:47 +0100)
We are pretty good at this already, hence only a single case is actually
found by this.

coccinelle/memzero.cocci [new file with mode: 0644]
src/journal/journald-server.c

diff --git a/coccinelle/memzero.cocci b/coccinelle/memzero.cocci
new file mode 100644 (file)
index 0000000..ebdc3f6
--- /dev/null
@@ -0,0 +1,30 @@
+@@
+expression s;
+@@
+- memset(&s, 0, sizeof(s))
++ zero(s)
+@@
+expression s;
+@@
+- memset(s, 0, sizeof(*s))
++ zero(*s)
+@@
+expression s;
+@@
+- bzero(&s, sizeof(s))
++ zero(s)
+@@
+expression s;
+@@
+- bzero(s, sizeof(*s))
++ zero(*s)
+@@
+expression a, b;
+@@
+- memset(a, 0, b)
++ memzero(a, b)
+@@
+expression a, b;
+@@
+- bzero(a, b)
++ memzero(a, b)
index 48375f9c3eaa857718b2907d6b06c6d9d14991d8..d68e3a8d519047cb09af628ed04f56c050c6c52d 100644 (file)
@@ -133,7 +133,7 @@ static int determine_path_usage(Server *s, const char *path, uint64_t *ret_used,
 }
 
 static void cache_space_invalidate(JournalStorageSpace *space) {
-        memset(space, 0, sizeof(*space));
+        zero(*space);
 }
 
 static int cache_space_refresh(Server *s, JournalStorage *storage) {