util: use xalloc instead of calloc to avoid NULL checks

This commit is contained in:
Peter Hutterer 2024-09-11 11:32:02 +10:00
parent bbc1f8de1c
commit 005c4ac493
2 changed files with 2 additions and 2 deletions

View file

@ -54,7 +54,7 @@ xread_with_fds(int fd, void *buf, size_t count, int **fds)
if (received > 0) {
*fds = NULL;
_cleanup_free_ int *fd_return = calloc(MAX_FDS + 1, sizeof(int));
_cleanup_free_ int *fd_return = xalloc(MAX_FDS + 1 * sizeof(int));
size_t idx = 0;
for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {

View file

@ -182,7 +182,7 @@ strreplace(const char *string, const char *separator, const char *replacement)
size_t rlen = strlen(replacement);
size_t max = slen * max(rlen, 1);
char *r = calloc(max + 1, 1); /* the result, one extra for terminating \0 */
char *r = xalloc(max + 1); /* the result, one extra for terminating \0 */
char *destptr = r;
while (next) {