Skip to content

Instantly share code, notes, and snippets.

@master-q
Last active September 30, 2016 06:04
Show Gist options
  • Save master-q/d96b31d9e048a2c74abc70cdbfb3de46 to your computer and use it in GitHub Desktop.
Save master-q/d96b31d9e048a2c74abc70cdbfb3de46 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <sys/types.h>
#define __infer_assert(E) \
int *s = NULL; \
if (!(E)) *s = 0xDEADBEEF;
int main() {
uid_t id;
id = getuid();
__infer_assert(id != 0);
}
$ infer -- gcc -c assert1.c
Starting analysis (Infer version v0.8.1)
F.
Analyzed 1 file
Found 1 issue
assert1.c:11: error: NULL_DEREFERENCE
pointer s last assigned on line 11 could be null and is dereferenced at line 11, column 2
9. uid_t id;
10. id = getuid();
11. > __infer_assert(id != 0);
12. }
13.
Summary of the reports
NULL_DEREFERENCE: 1
$ gcc assert1.c
$ ./a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment