logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 7ecc44801826f8a3c80b093851ace4357e266a45
parent 51b51a7d99fb19b31719d4ab7f19e34bf514211f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 13 Sep 2024 23:18:51 +0200

cmd/id: use calloc for arrays

Diffstat:

Mcmd/id.c7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/cmd/id.c b/cmd/id.c @@ -7,7 +7,7 @@ #include <pwd.h> // getpwuid #include <stdbool.h> // bool #include <stdio.h> // printf, perror -#include <stdlib.h> // malloc, free +#include <stdlib.h> // calloc, free #include <sys/types.h> // uid_t #include <unistd.h> // getuid, getgid, getopt, opt*, getgrouplist(FreeBSD, NetBSD) @@ -165,10 +165,11 @@ main(int argc, char *argv[]) int ngroups = 0; int ngroups_max = (int)sysconf(_SC_NGROUPS_MAX) + 1; - gid_t *groups = malloc(sizeof(gid_t) * ngroups_max); + gid_t *groups = NULL; + groups = calloc(ngroups_max, sizeof(*groups)); if(groups == NULL) { - perror("id: malloc(groups)"); + perror("id: calloc(groups)"); return 1; }