#include "sizeof.h"
-#define CALLOC(n, T) CALLOC_(n, typeas(T))
-#define CALLOC_(n, T) \
+// calloc_T - calloc type-safe
+#define calloc_T(n, T) calloc_T_(n, typeas(T))
+#define calloc_T_(n, T) \
({ \
(T *){calloc(n, sizeof(T))}; \
})
-#define XCALLOC(n, T) exit_if_null(CALLOC(n, T))
+#define XCALLOC(n, T) exit_if_null(calloc_T(n, T))
#endif // include guard
*/
/* Create an array to hold all of the discovered GIDs */
- used_gids = CALLOC (gid_max + 1, bool);
+ used_gids = calloc_T(gid_max + 1, bool);
if (NULL == used_gids) {
fprintf (log_get_logfd(),
_("%s: failed to allocate memory: %s\n"),
*/
/* Create an array to hold all of the discovered UIDs */
- used_uids = CALLOC(uid_max + 1, bool);
+ used_uids = calloc_T(uid_max + 1, bool);
if (NULL == used_uids) {
fprintf (log_get_logfd(),
_("%s: failed to allocate memory: %s\n"),
members++;
}
}
- new_members = CALLOC (members + 1, char *);
+ new_members = calloc_T(members + 1, char *);
if (NULL == new_members) {
free(new_line);
return NULL;
struct group *gr;
int i;
- gr = CALLOC(1, struct group);
+ gr = calloc_T(1, struct group);
if (NULL == gr) {
return NULL;
}
return NULL;
}
- mappings = CALLOC(ranges, struct map_range);
+ mappings = calloc_T(ranges, struct map_range);
if (!mappings) {
fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"),
log_get_progname());
return PAM_CONV_ERR;
}
- responses = CALLOC (num_msg, struct pam_response);
+ responses = calloc_T(num_msg, struct pam_response);
if (NULL == responses) {
return PAM_CONV_ERR;
}
{
struct passwd *pw;
- pw = CALLOC (1, struct passwd);
+ pw = calloc_T(1, struct passwd);
if (NULL == pw) {
return NULL;
}
struct sgrp *sg;
int i;
- sg = CALLOC (1, struct sgrp);
+ sg = calloc_T(1, struct sgrp);
if (NULL == sg) {
return NULL;
}
{
struct spwd *sp;
- sp = CALLOC (1, struct spwd);
+ sp = calloc_T(1, struct spwd);
if (NULL == sp) {
return NULL;
}