forked from merbanan/rtl_433
-
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.
Add warnings on alloc failure, enforce alloc check style
- Loading branch information
1 parent
78a4fbe
commit de8f73b
Showing
16 changed files
with
270 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** @file | ||
Fatal abort and warning macros for allocs. | ||
Copyright (C) 2019 Christian W. Zuckschwerdt <[email protected]> | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
*/ | ||
|
||
#ifndef INCLUDE_FATAL_H_ | ||
#define INCLUDE_FATAL_H_ | ||
|
||
#define STR(x) #x | ||
#define STRINGIFY(x) STR(x) | ||
#define FILE_LINE __FILE__ ":" STRINGIFY(__LINE__) | ||
#define FATAL(what) do { fprintf(stderr, "FATAL: " what " from " FILE_LINE "\n"); exit(1); } while (0) | ||
#define FATAL_MALLOC(what) FATAL("low memory? malloc() failed in " what) | ||
#define FATAL_CALLOC(what) FATAL("low memory? calloc() failed in " what) | ||
#define FATAL_REALLOC(what) FATAL("low memory? realloc() failed in " what) | ||
#define FATAL_STRDUP(what) FATAL("low memory? strdup() failed in " what) | ||
#define WARN(what) fprintf(stderr, "WARNING: " what " from " FILE_LINE "\n") | ||
#define WARN_MALLOC(what) WARN("low memory? malloc() failed in " what) | ||
#define WARN_CALLOC(what) WARN("low memory? calloc() failed in " what) | ||
#define WARN_REALLOC(what) WARN("low memory? realloc() failed in " what) | ||
#define WARN_STRDUP(what) WARN("low memory? strdup() failed in " what) | ||
|
||
/* | ||
Use like this: | ||
char *buf = malloc(size); | ||
if (!buf) | ||
FATAL_MALLOC("my_func()"); | ||
*/ | ||
|
||
#endif /* INCLUDE_FATAL_H_ */ |
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
Oops, something went wrong.