bb4267
From 7acf0fad0ca468f33f86084f36251df5baf3dc94 Mon Sep 17 00:00:00 2001
bb4267
From: Jakub Hrozek <jakub.hrozek@posteo.se>
bb4267
Date: Wed, 26 Sep 2018 21:01:59 +0200
bb4267
Subject: [PATCH 5/7] files.c: Init char *name to NULL
bb4267
bb4267
Merges:
bb4267
https://pagure.io/libuser/issue/27
bb4267
bb4267
This is mostly to silence coverity warnings. "enum lu_entity_type" has
bb4267
three values and several places in the code follow logic as:
bb4267
bb4267
char *name;
bb4267
if ent->type == user:
bb4267
        name = foo()
bb4267
if ent->type == group
bb4267
        name = bar()
bb4267
g_assert(name != NULL)
bb4267
bb4267
it shouldn't be possible for ent->type to be anything else but in the
bb4267
odd case it is, initializing name to NULL will ensure that name will be
bb4267
still NULL after the code falls through the conditions and at least the
bb4267
behaviour is defined.
bb4267
---
bb4267
 modules/files.c | 6 +++---
bb4267
 1 file changed, 3 insertions(+), 3 deletions(-)
bb4267
bb4267
diff --git a/modules/files.c b/modules/files.c
bb4267
index 6a7787e28112ba07e0fc44f2887ce1d1540af29e..8c2a282b6448bbfb313b5d4f5eeb28b8240bccd5 100644
bb4267
--- a/modules/files.c
bb4267
+++ b/modules/files.c
bb4267
@@ -1501,7 +1501,7 @@ generic_lock(struct lu_module *module, const char *file_suffix, int field,
bb4267
 	     struct lu_ent *ent, enum lock_op op, struct lu_error **error)
bb4267
 {
bb4267
 	struct editing *e;
bb4267
-	char *value, *new_value, *name;
bb4267
+	char *value, *new_value, *name = NULL;
bb4267
 	gboolean commit = FALSE, ret = FALSE;
bb4267
 
bb4267
 	/* Get the name which keys the entries of interest in the file. */
bb4267
@@ -1561,7 +1561,7 @@ generic_is_locked(struct lu_module *module, const char *file_suffix,
bb4267
 		  int field, struct lu_ent *ent, struct lu_error **error)
bb4267
 {
bb4267
 	char *filename;
bb4267
-	char *value, *name;
bb4267
+	char *value, *name = NULL;
bb4267
 	int fd;
bb4267
 	gboolean ret = FALSE;
bb4267
 
bb4267
@@ -1752,7 +1752,7 @@ generic_setpass(struct lu_module *module, const char *file_suffix, int field,
bb4267
 		struct lu_error **error)
bb4267
 {
bb4267
 	struct editing *e;
bb4267
-	char *value, *name;
bb4267
+	char *value, *name = NULL;
bb4267
 	gboolean ret = FALSE;
bb4267
 
bb4267
 	/* Get the name of this account. */
bb4267
-- 
bb4267
2.14.4
bb4267