forked from martinpitt/umockdev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce *x() wrappers for strdup(), malloc(), and calloc() which abort on ENOMEM. Fixes `-Wanalyzer-possible-null-dereference` warnings.
- Loading branch information
1 parent
92c8a00
commit ec6f986
Showing
7 changed files
with
65 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "utils.h" | ||
|
||
static void | ||
abort_errno (const char *msg) | ||
{ | ||
perror (msg); | ||
abort (); | ||
} | ||
|
||
void * | ||
callocx (size_t nmemb, size_t size) | ||
{ | ||
void *r = calloc (nmemb, size); | ||
if (r == NULL) | ||
abort_errno ("failed to allocate memory"); | ||
return r; | ||
} | ||
|
||
void * | ||
mallocx (size_t size) | ||
{ | ||
void *r = malloc (size); | ||
if (r == NULL) | ||
abort_errno ("failed to allocate memory"); | ||
return r; | ||
} | ||
|
||
|
||
char * | ||
strdupx (const char *s) | ||
{ | ||
char *r = strdup (s); | ||
if (r == NULL) | ||
abort_errno ("failed to allocate memory for strdup"); | ||
return r; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
/* variants of glibc functions that abort() on ENOMEM */ | ||
void *mallocx (size_t size); | ||
void *callocx (size_t nmemb, size_t size); | ||
char *strdupx (const char *s); |