Skip to content

Commit db12a09

Browse files
Add NULL fd test for vfscanf and vfprintf
1 parent f2e69af commit db12a09

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clang/test/Analysis/Inputs/system-header-simulator-for-valist.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ int vprintf (const char *restrict format, va_list arg);
2323

2424
int vsprintf (char *restrict s, const char *restrict format, va_list arg);
2525

26+
int vfprintf(FILE *stream, const char *format, va_list ap);
27+
2628
int vfscanf(FILE *stream, const char *format, va_list ap);
2729

2830
int some_library_function(int n, va_list arg);

clang/test/Analysis/stream.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.Stream,debug.ExprInspection -verify %s
22

33
#include "Inputs/system-header-simulator.h"
4+
#include "Inputs/system-header-simulator-for-valist.h"
45

56
void clang_analyzer_eval(int);
67

@@ -141,6 +142,18 @@ void f_dopen(int fd) {
141142
fclose(F);
142143
}
143144

145+
void f_vfprintf(int fd, va_list args) {
146+
FILE *F = fdopen(fd, "r");
147+
vfprintf(F, "%d", args); // expected-warning {{Stream pointer might be NULL}}
148+
fclose(F);
149+
}
150+
151+
void f_vfscanf(int fd, va_list args) {
152+
FILE *F = fdopen(fd, "r");
153+
vfscanf(F, "%u", args); // expected-warning {{Stream pointer might be NULL}}
154+
fclose(F);
155+
}
156+
144157
void f_seek(void) {
145158
FILE *p = fopen("foo", "r");
146159
if (!p)

0 commit comments

Comments
 (0)