Skip to contentSkip to conversation

main - gcc-fanalyzer: use zeroed memory

PATCH Zdenek Kabelac 1 participant 1 message Sep 20, 2021

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=93d565eda992abc0460cc8fc7b9998bd1996a447
Commit:        93d565eda992abc0460cc8fc7b9998bd1996a447
Parent:        5126ac7c3aa4f9f47a36c66095246d5b13871e61
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Sat Sep 18 21:01:48 2021 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Sep 20 13:58:57 2021 +0200

gcc-fanalyzer: use zeroed memory

Analyzer here was rather confused about possiblity of loosing previously assigned device pointers - fixed by passing zero initialize memory before first assign.

---
 daemons/dmeventd/dmeventd.c | 2 +-
 tools/vgimportclone.c       | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
daemons/dmeventd/dmeventd.c +1 -1
index 041718c7a..c44fa4ed9 100644
@@ -2069,7 +2069,7 @@ static void _restart_dmeventd(void)
 			++count;
 		}
 
-	if (!(_initial_registrations = malloc(sizeof(char*) * (count + 1)))) {
+	if (!(_initial_registrations = zalloc(sizeof(char*) * (count + 1)))) {
 		fprintf(stderr, "Memory allocation registration failed.\n");
 		goto bad;
 	}
tools/vgimportclone.c +2 -2
index 8aa0dbba9..23bb6271f 100644
@@ -194,7 +194,7 @@ static int _get_other_devs(struct cmd_context *cmd, struct dm_list *new_devs, st
 	while ((dev = dev_iter_get(cmd, iter))) {
 		if (_get_device_list(new_devs, dev))
 			continue;
-		if (!(devl = malloc(sizeof(*devl)))) {
+		if (!(devl = zalloc(sizeof(*devl)))) {
 			r = 0;
 			goto_bad;
 		}
@@ -278,7 +278,7 @@ int vgimportclone(struct cmd_context *cmd, int argc, char **argv)
 			goto out;
 		}
 
-		if (!(devl = malloc(sizeof(*devl))))
+		if (!(devl = zalloc(sizeof(*devl))))
 			goto_out;
 
 		devl->dev = dev;