Use safer allocation macros

Use of these macros, apart from the benefits mentioned in the commit
that adds the macros, has some other good side effects:

-  Consistency in getting the size of the object from sizeof(type),
   instead of a mix of sizeof(type) sometimes and sizeof(*p) other
   times.

-  More readable code: no casts, and no sizeof(), so also shorter lines
   that we don't need to cut.

-  Consistency in using array allocation calls for allocations of arrays
   of objects, even when the object size is 1.

Cc: Valentin V. Bartenev <vbartenev@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-02-04 22:41:18 +01:00
committed by Serge Hallyn
parent 6e58c12752
commit efbbcade43
44 changed files with 196 additions and 118 deletions
+3 -1
View File
@@ -19,6 +19,8 @@
#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include "alloc.h"
#include "defines.h"
#include "groupio.h"
#include "nscd.h"
@@ -834,7 +836,7 @@ static void get_group (struct group *gr)
sg->sg_mem = dup_list (gr->gr_mem);
sg->sg_adm = (char **) xmallocarray (2, sizeof (char *));
sg->sg_adm = XMALLOCARRAY (2, char *);
#ifdef FIRST_MEMBER_IS_ADMIN
if (sg->sg_mem[0]) {
sg->sg_adm[0] = xstrdup (sg->sg_mem[0]);