brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · c3a6302 Raw
170 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Stream,unix.StdCLibraryFunctions,debug.ExprInspection \2// RUN:   -analyzer-config unix.Stream:Pedantic=true \3// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s4 5// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Stream,debug.ExprInspection \6// RUN:   -analyzer-config unix.Stream:Pedantic=true \7// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stream,any %s8 9// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.StdCLibraryFunctions,debug.ExprInspection \10// RUN:   -analyzer-config unix.Stream:Pedantic=true \11// RUN:   -analyzer-config unix.StdCLibraryFunctions:ModelPOSIX=true -verify=stdfunc,any %s12 13#include "Inputs/system-header-simulator.h"14 15extern void clang_analyzer_eval(int);16 17void *buf;18size_t size;19size_t n;20 21void test_fopen(void) {22  FILE *fp = fopen("path", "r");23  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}} any-warning{{FALSE}}24  fclose(fp); // \25  // stream-warning{{Stream pointer might be NULL}} \26  // stdfunc-warning{{should not be NULL}}27}28 29void test_fdopen(int fd) {30  FILE *fp = fdopen(fd, "r");31  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}} any-warning{{FALSE}}32  fclose(fp); // \33  // stream-warning{{Stream pointer might be NULL}} \34  // stdfunc-warning{{should not be NULL}}35}36 37void test_tmpfile(void) {38  FILE *fp = tmpfile();39  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}} any-warning{{FALSE}}40  fclose(fp); // \41  // stream-warning{{Stream pointer might be NULL}} \42  // stdfunc-warning{{should not be NULL}}43}44 45void test_fclose(void) {46  FILE *fp = tmpfile();47  fclose(fp); // \48  // stream-warning{{Stream pointer might be NULL}} \49  // stdfunc-warning{{should not be NULL}}50  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}51}52 53void test_freopen(void) {54  FILE *fp = tmpfile();55  fp = freopen("file", "w", fp); // \56  // stream-warning{{Stream pointer might be NULL}} \57  // stdfunc-warning{{should not be NULL}}58  fclose(fp); // \59  // stream-warning{{Stream pointer might be NULL}} \60  // stdfunc-warning{{should not be NULL}}61  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}62}63 64void test_fread(void) {65  FILE *fp = tmpfile();66  size_t ret = fread(buf, size, n, fp); // \67  // stream-warning{{Stream pointer might be NULL}} \68  // stdfunc-warning{{The 4th argument to 'fread' is NULL but should not be NULL}}69  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}70  clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}71  clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}72 73  fclose(fp);74}75 76void test_fwrite(void) {77  FILE *fp = tmpfile();78  size_t ret = fwrite(buf, size, n, fp); // \79  // stream-warning{{Stream pointer might be NULL}} \80  // stdfunc-warning{{The 4th argument to 'fwrite' is NULL but should not be NULL}}81  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}82  clang_analyzer_eval(ret <= n); // any-warning{{TRUE}}83  clang_analyzer_eval(ret == n); // any-warning{{TRUE}} any-warning{{FALSE}}84 85  fclose(fp);86}87 88void test_fseek(void) {89  FILE *fp = tmpfile();90  fseek(fp, 0, 0); // \91  // stream-warning{{Stream pointer might be NULL}} \92  // stdfunc-warning{{should not be NULL}}93  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}94  fclose(fp);95}96 97void test_ftell(void) {98  FILE *fp = tmpfile();99  ftell(fp); // \100  // stream-warning{{Stream pointer might be NULL}} \101  // stdfunc-warning{{should not be NULL}}102  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}103  fclose(fp);104}105 106void test_rewind(void) {107  FILE *fp = tmpfile();108  rewind(fp); // \109  // stream-warning{{Stream pointer might be NULL}} \110  // stdfunc-warning{{should not be NULL}}111  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}112  fclose(fp);113}114 115void test_fgetpos(void) {116  FILE *fp = tmpfile();117  fpos_t pos;118  fgetpos(fp, &pos); // \119  // stream-warning{{Stream pointer might be NULL}} \120  // stdfunc-warning{{should not be NULL}}121  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}122  fclose(fp);123}124 125void test_fsetpos(void) {126  FILE *fp = tmpfile();127  fpos_t pos;128  fsetpos(fp, &pos); // \129  // stream-warning{{Stream pointer might be NULL}} \130  // stdfunc-warning{{should not be NULL}}131  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}132  fclose(fp);133}134 135void test_clearerr(void) {136  FILE *fp = tmpfile();137  clearerr(fp); // \138  // stream-warning{{Stream pointer might be NULL}} \139  // stdfunc-warning{{should not be NULL}}140  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}141  fclose(fp);142}143 144void test_feof(void) {145  FILE *fp = tmpfile();146  feof(fp); // \147  // stream-warning{{Stream pointer might be NULL}} \148  // stdfunc-warning{{should not be NULL}}149  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}150  fclose(fp);151}152 153void test_ferror(void) {154  FILE *fp = tmpfile();155  ferror(fp); // \156  // stream-warning{{Stream pointer might be NULL}} \157  // stdfunc-warning{{should not be NULL}}158  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}159  fclose(fp);160}161 162void test_fileno(void) {163  FILE *fp = tmpfile();164  fileno(fp); // \165  // stream-warning{{Stream pointer might be NULL}} \166  // stdfunc-warning{{should not be NULL}}167  clang_analyzer_eval(fp != NULL); // any-warning{{TRUE}}168  fclose(fp);169}170