#31 files.c: Init char *name to NULL
Merged a year ago by jhrozek. Opened a year ago by jhrozek.
jhrozek/libuser init_name_to_null  into  master

file modified
+3 -3

@@ -1501,7 +1501,7 @@ 

  	     struct lu_ent *ent, enum lock_op op, struct lu_error **error)

  {

  	struct editing *e;

- 	char *value, *new_value, *name;

+ 	char *value, *new_value, *name = NULL;

  	gboolean commit = FALSE, ret = FALSE;

  

  	/* Get the name which keys the entries of interest in the file. */

@@ -1561,7 +1561,7 @@ 

  		  int field, struct lu_ent *ent, struct lu_error **error)

  {

  	char *filename;

- 	char *value, *name;

+ 	char *value, *name = NULL;

  	int fd;

  	gboolean ret = FALSE;

  

@@ -1752,7 +1752,7 @@ 

  		struct lu_error **error)

  {

  	struct editing *e;

- 	char *value, *name;

+ 	char *value, *name = NULL;

  	gboolean ret = FALSE;

  

  	/* Get the name of this account. */

This is mostly to silence coverity warnings. "enum lu_entity_type" has
three values and several places in the code follow logic as:

char *name;
if ent->type == user:
name = foo()
if ent->type == group
name = bar()
g_assert(name != NULL)

it shouldn't be possible for ent->type to be anything else but in the
odd case it is, initializing name to NULL will ensure that name will be
still NULL after the code falls through the conditions and at least the
behaviour is defined.

rebased onto 7acf0fa

a year ago

Commit 38021b6 fixes this pull-request

Pull-Request has been merged by jhrozek

a year ago

Pull-Request has been merged by jhrozek

a year ago
Metadata