[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / cert / env34-c-cert-examples.c
blob19ca73f34c7ee5e24d5bd1e2a49ece9ac32549ea
1 // RUN: %clang_analyze_cc1 \
2 // RUN: -analyzer-checker=core,alpha.security.cert.env.InvalidPtr \
3 // RUN: -verify -Wno-unused %s
5 #include "../Inputs/system-header-simulator.h"
6 char *getenv(const char *name);
7 int strcmp(const char*, const char*);
8 char *strdup(const char*);
9 void free(void *memblock);
10 void *malloc(size_t size);
12 void incorrect_usage(void) {
13 char *tmpvar;
14 char *tempvar;
16 tmpvar = getenv("TMP");
18 if (!tmpvar)
19 return;
21 tempvar = getenv("TEMP");
23 if (!tempvar)
24 return;
26 if (strcmp(tmpvar, tempvar) == 0) { // body of strcmp is unknown
27 // expected-warning@-1{{use of invalidated pointer 'tmpvar' in a function call}}
31 void correct_usage_1(void) {
32 char *tmpvar;
33 char *tempvar;
35 const char *temp = getenv("TMP");
36 if (temp != NULL) {
37 tmpvar = (char *)malloc(strlen(temp)+1);
38 if (tmpvar != NULL) {
39 strcpy(tmpvar, temp);
40 } else {
41 return;
43 } else {
44 return;
47 temp = getenv("TEMP");
48 if (temp != NULL) {
49 tempvar = (char *)malloc(strlen(temp)+1);
50 if (tempvar != NULL) {
51 strcpy(tempvar, temp);
52 } else {
53 return;
55 } else {
56 return;
59 if (strcmp(tmpvar, tempvar) == 0) {
60 printf("TMP and TEMP are the same.\n");
61 } else {
62 printf("TMP and TEMP are NOT the same.\n");
64 free(tmpvar);
65 free(tempvar);
68 void correct_usage_2(void) {
69 char *tmpvar;
70 char *tempvar;
72 const char *temp = getenv("TMP");
73 if (temp != NULL) {
74 tmpvar = strdup(temp);
75 if (tmpvar == NULL) {
76 return;
78 } else {
79 return;
82 temp = getenv("TEMP");
83 if (temp != NULL) {
84 tempvar = strdup(temp);
85 if (tempvar == NULL) {
86 return;
88 } else {
89 return;
92 if (strcmp(tmpvar, tempvar) == 0) {
93 printf("TMP and TEMP are the same.\n");
94 } else {
95 printf("TMP and TEMP are NOT the same.\n");
97 free(tmpvar);
98 tmpvar = NULL;
99 free(tempvar);
100 tempvar = NULL;