* Let's add one more byte, and if the password uses it, it
* means the introduced password was longer than PASS_MAX.
*/
- pass = MALLOC(PASS_MAX + 2, char);
+ pass = malloc_T(PASS_MAX + 2, char);
if (pass == NULL)
return NULL;
#include "sizeof.h"
-#define MALLOC(n, T) MALLOC_(n, typeas(T))
-#define MALLOC_(n, T) \
+// malloc_T - malloc type-safe
+#define malloc_T(n, T) malloc_T_(n, typeas(T))
+#define malloc_T_(n, T) \
({ \
(T *){mallocarray(n, sizeof(T))}; \
})
-#define XMALLOC(n, T) exit_if_null(MALLOC(n, T))
+#define XMALLOC(n, T) exit_if_null(malloc_T(n, T))
+// mallocarray - malloc array
ATTR_ALLOC_SIZE(1, 2)
ATTR_MALLOC(free)
inline void *mallocarray(size_t nmemb, size_t size);
}
}
- p = MALLOC(1, struct commonio_entry);
+ p = malloc_T(1, struct commonio_entry);
if (NULL == p) {
goto cleanup_entry;
}
return 0;
}
- entries = MALLOC(n, struct commonio_entry *);
+ entries = malloc_T(n, struct commonio_entry *);
if (entries == NULL) {
return -1;
}
return 1;
}
/* not found, new entry */
- p = MALLOC(1, struct commonio_entry);
+ p = malloc_T(1, struct commonio_entry);
if (NULL == p) {
db->ops->cio_free(nentry);
errno = ENOMEM;
return 0;
}
/* new entry */
- p = MALLOC(1, struct commonio_entry);
+ p = malloc_T(1, struct commonio_entry);
if (NULL == p) {
db->ops->cio_free(nentry);
errno = ENOMEM;
int len;
char *buf;
- buf = MALLOC(size, char);
+ buf = malloc_T(size, char);
if (NULL == buf)
return NULL;
continue;
}
- new = MALLOC(1, struct commonio_entry);
+ new = malloc_T(1, struct commonio_entry);
if (NULL == new) {
return 0;
}
for (i = 0; grent->gr_mem[i]; i++);
/*@-mustfreeonly@*/
- gr->gr_mem = MALLOC(i + 1, char *);
+ gr->gr_mem = malloc_T(i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == gr->gr_mem) {
gr_free(gr);
fprintf(shadow_logfd, "Using files\n");
goto null_subid;
}
- subid_nss = MALLOC(1, struct subid_nss_ops);
+ subid_nss = malloc_T(1, struct subid_nss_ops);
if (!subid_nss) {
goto close_lib;
}
for (i = 0; NULL != sgent->sg_adm[i]; i++);
/*@-mustfreeonly@*/
- sg->sg_adm = MALLOC(i + 1, char *);
+ sg->sg_adm = malloc_T(i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == sg->sg_adm) {
free (sg->sg_passwd);
for (i = 0; NULL != sgent->sg_mem[i]; i++);
/*@-mustfreeonly@*/
- sg->sg_mem = MALLOC(i + 1, char *);
+ sg->sg_mem = malloc_T(i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == sg->sg_mem) {
for (i = 0; NULL != sg->sg_adm[i]; i++) {
n = n ?: 1;
- gids = MALLOC(n, gid_t);
+ gids = malloc_T(n, gid_t);
if (gids == NULL)
return NULL;
size += strlen (sgrp->sg_mem[i]) + 1;
}
- buf = MALLOC(size, char);
+ buf = malloc_T(size, char);
if (NULL == buf) {
return -1;
}
if (rv == -1 && errno == ENOENT)
return 0;
- sss_cache_args = MALLOC(4, char);
+ sss_cache_args = malloc_T(4, char);
if (sss_cache_args == NULL) {
return -1;
}
n = strchrscnt(s, delim) + 2;
- ls = MALLOC(n, char *);
+ ls = malloc_T(n, char *);
if (ls == NULL)
return NULL;
const struct subordinate_range *rangeent = ent;
struct subordinate_range *range;
- range = MALLOC(1, struct subordinate_range);
+ range = malloc_T(1, struct subordinate_range);
if (NULL == range) {
return NULL;
}
/* we have to start with something */
size_t length = 0x100;
- result = MALLOC(1, LOOKUP_TYPE);
+ result = malloc_T(1, LOOKUP_TYPE);
if (NULL == result) {
goto oom;
}
if (range.first > range.last)
return 0;
- entry = MALLOC(1, struct id_range_list_entry);
+ entry = malloc_T(1, struct id_range_list_entry);
if (!entry) {
fprintf (stderr,
_("%s: failed to allocate memory: %s\n"),
}
static int alloc_uid(uid_t **uids, uid_t id) {
- *uids = MALLOC(1, uid_t);
+ *uids = malloc_T(1, uid_t);
if (!*uids)
return -1;
*uids[0] = id;
return SUBID_STATUS_SUCCESS;
if (id_type == ID_TYPE_UID && strcmp(owner, "group1") == 0)
return SUBID_STATUS_SUCCESS;
- ranges = MALLOC(1, struct subid_range);
+ ranges = malloc_T(1, struct subid_range);
if (!ranges)
return SUBID_STATUS_ERROR;
if (strcmp(owner, "user1") == 0 || strcmp(owner, "group1") == 0) {
char *name;
max = sysconf(_SC_LOGIN_NAME_MAX);
- name = MALLOC(max + 1, char);
+ name = malloc_T(max + 1, char);
assert_true(name != NULL);
memset(name, '_', max);