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:
committed by
Serge Hallyn
parent
6e58c12752
commit
efbbcade43
@@ -14,6 +14,7 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "commonio.h"
|
||||
@@ -25,7 +26,7 @@
|
||||
struct sgrp *sg;
|
||||
int i;
|
||||
|
||||
sg = (struct sgrp *) calloc (1, sizeof *sg);
|
||||
sg = CALLOC (1, struct sgrp);
|
||||
if (NULL == sg) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -49,7 +50,7 @@
|
||||
|
||||
for (i = 0; NULL != sgent->sg_adm[i]; i++);
|
||||
/*@-mustfreeonly@*/
|
||||
sg->sg_adm = (char **) mallocarray (i + 1, sizeof (char *));
|
||||
sg->sg_adm = MALLOCARRAY (i + 1, char *);
|
||||
/*@=mustfreeonly@*/
|
||||
if (NULL == sg->sg_adm) {
|
||||
free (sg->sg_passwd);
|
||||
@@ -74,7 +75,7 @@
|
||||
|
||||
for (i = 0; NULL != sgent->sg_mem[i]; i++);
|
||||
/*@-mustfreeonly@*/
|
||||
sg->sg_mem = (char **) mallocarray (i + 1, sizeof (char *));
|
||||
sg->sg_mem = MALLOCARRAY (i + 1, char *);
|
||||
/*@=mustfreeonly@*/
|
||||
if (NULL == sg->sg_mem) {
|
||||
for (i = 0; NULL != sg->sg_adm[i]; i++) {
|
||||
|
Reference in New Issue
Block a user