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) {
16 tmpvar
= getenv("TMP");
21 tempvar
= getenv("TEMP");
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) {
35 const char *temp
= getenv("TMP");
37 tmpvar
= (char *)malloc(strlen(temp
)+1);
47 temp
= getenv("TEMP");
49 tempvar
= (char *)malloc(strlen(temp
)+1);
50 if (tempvar
!= NULL
) {
51 strcpy(tempvar
, temp
);
59 if (strcmp(tmpvar
, tempvar
) == 0) {
60 printf("TMP and TEMP are the same.\n");
62 printf("TMP and TEMP are NOT the same.\n");
68 void correct_usage_2(void) {
72 const char *temp
= getenv("TMP");
74 tmpvar
= strdup(temp
);
82 temp
= getenv("TEMP");
84 tempvar
= strdup(temp
);
85 if (tempvar
== NULL
) {
92 if (strcmp(tmpvar
, tempvar
) == 0) {
93 printf("TMP and TEMP are the same.\n");
95 printf("TMP and TEMP are NOT the same.\n");