if (gids == NULL)
return -1;
- gids = REALLOCF(gids, n + strchrscnt(list, ",:") + 1, gid_t);
+ gids = reallocf_T(gids, n + strchrscnt(list, ",:") + 1, gid_t);
if (gids == NULL)
return -1;
#include "sizeof.h"
-#define REALLOCF(p, n, T) REALLOCF_(p, n, typeas(T))
-#define REALLOCF_(p, n, T) \
+// reallocf_T - realloc free-on-error type-safe
+#define reallocf_T(p, n, T) reallocf_T_(p, n, typeas(T))
+#define reallocf_T_(p, n, T) \
({ \
_Generic(p, T *: (void)0); \
(T *){reallocarrayf_(p, n, sizeof(T))}; \
#define reallocarrayf_(p, n, size) reallocarrayf(p, (n) ?: 1, (size) ?: 1)
+// reallocarrayf - realloc array free-on-error
ATTR_ALLOC_SIZE(2, 3)
ATTR_MALLOC(free)
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
return n;
}
- *uids = REALLOCF(*uids, n + 1, uid_t);
+ *uids = reallocf_T(*uids, n + 1, uid_t);
if (!*uids)
return -1;
#ifdef USE_PAM
/* keep the list of user/password for later update by PAM */
nusers++;
- lines = REALLOCF(lines, nusers, intmax_t);
- usernames = REALLOCF(usernames, nusers, char *);
- passwords = REALLOCF(passwords, nusers, char *);
+ lines = reallocf_T(lines, nusers, intmax_t);
+ usernames = reallocf_T(usernames, nusers, char *);
+ passwords = reallocf_T(passwords, nusers, char *);
if (lines == NULL || usernames == NULL || passwords == NULL) {
fprintf(stderr, _("%s: line %jd: %s\n"), Prog, line, strerrno());
fail_exit (EXIT_FAILURE, process_selinux);