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
@@ -45,6 +45,8 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#endif /* !USE_PAM */
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "pwauth.h"
|
||||
@@ -238,7 +240,7 @@ static void execve_shell (const char *shellname,
|
||||
while (NULL != args[n_args]) {
|
||||
n_args++;
|
||||
}
|
||||
targs = (char **) xmallocarray (n_args + 3, sizeof (args[0]));
|
||||
targs = XMALLOCARRAY (n_args + 3, char *);
|
||||
targs[0] = "sh";
|
||||
targs[1] = "-";
|
||||
targs[2] = xstrdup (shellname);
|
||||
@@ -1176,7 +1178,7 @@ int main (int argc, char **argv)
|
||||
cp = Basename (shellstr);
|
||||
}
|
||||
|
||||
arg0 = xmalloc (strlen (cp) + 2);
|
||||
arg0 = XMALLOCARRAY (strlen (cp) + 2, char);
|
||||
arg0[0] = '-';
|
||||
strcpy (arg0 + 1, cp);
|
||||
cp = arg0;
|
||||
|
||||
Reference in New Issue
Block a user