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
@@ -30,6 +30,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog.h"
|
||||
|
||||
@@ -50,7 +52,7 @@
|
||||
/* we have to start with something */
|
||||
size_t length = 0x100;
|
||||
|
||||
result = malloc(sizeof(LOOKUP_TYPE));
|
||||
result = MALLOC(LOOKUP_TYPE);
|
||||
if (NULL == result) {
|
||||
fprintf (log_get_logfd(), _("%s: out of memory\n"),
|
||||
"x" STRINGIZE(FUNCTION_NAME));
|
||||
@@ -60,7 +62,7 @@
|
||||
while (true) {
|
||||
int status;
|
||||
LOOKUP_TYPE *resbuf = NULL;
|
||||
buffer = (char *)xreallocarray (buffer, length, sizeof(char));
|
||||
buffer = XREALLOCARRAY (buffer, length, char);
|
||||
status = REENTRANT_NAME(ARG_NAME, result, buffer,
|
||||
length, &resbuf);
|
||||
if ((0 == status) && (resbuf == result)) {
|
||||
|
Reference in New Issue
Block a user