#include "Inputs/system-header-simulator.h"
void check_fread(void) {
FILE *fp = tmpfile();
fread(0, 0, 0, fp); fclose(fp);
}
void check_fwrite(void) {
FILE *fp = tmpfile();
fwrite(0, 0, 0, fp); fclose(fp);
}
void check_fseek(void) {
FILE *fp = tmpfile();
fseek(fp, 0, 0); fclose(fp);
}
void check_ftell(void) {
FILE *fp = tmpfile();
ftell(fp); fclose(fp);
}
void check_rewind(void) {
FILE *fp = tmpfile();
rewind(fp); fclose(fp);
}
void check_fgetpos(void) {
FILE *fp = tmpfile();
fpos_t pos;
fgetpos(fp, &pos); fclose(fp);
}
void check_fsetpos(void) {
FILE *fp = tmpfile();
fpos_t pos;
fsetpos(fp, &pos); fclose(fp);
}
void check_clearerr(void) {
FILE *fp = tmpfile();
clearerr(fp); fclose(fp);
}
void check_feof(void) {
FILE *fp = tmpfile();
feof(fp); fclose(fp);
}
void check_ferror(void) {
FILE *fp = tmpfile();
ferror(fp); fclose(fp);
}
void check_fileno(void) {
FILE *fp = tmpfile();
fileno(fp); fclose(fp);
}
void f_open(void) {
FILE *p = fopen("foo", "r");
char buf[1024];
fread(buf, 1, 1, p); fclose(p);
}
void f_seek(void) {
FILE *p = fopen("foo", "r");
if (!p)
return;
fseek(p, 1, SEEK_SET); fseek(p, 1, 3); fclose(p);
}
void f_double_close(void) {
FILE *p = fopen("foo", "r");
if (!p)
return;
fclose(p);
fclose(p); }
void f_double_close_alias(void) {
FILE *p1 = fopen("foo", "r");
if (!p1)
return;
FILE *p2 = p1;
fclose(p1);
fclose(p2); }
void f_use_after_close(void) {
FILE *p = fopen("foo", "r");
if (!p)
return;
fclose(p);
clearerr(p); }
void f_open_after_close(void) {
FILE *p = fopen("foo", "r");
if (!p)
return;
fclose(p);
p = fopen("foo", "r");
if (!p)
return;
fclose(p);
}
void f_reopen_after_close(void) {
FILE *p = fopen("foo", "r");
if (!p)
return;
fclose(p);
p = freopen("foo", "w", p);
if (!p)
return;
fclose(p);
}
void f_leak(int c) {
FILE *p = fopen("foo.c", "r");
if (!p)
return;
if(c)
return; fclose(p);
}
FILE *f_null_checked(void) {
FILE *p = fopen("foo.c", "r");
if (p)
return p; else
return 0;
}
void pr7831(FILE *fp) {
fclose(fp); }
void pr8081(FILE *stream, long offset, int whence) {
fseek(stream, offset, whence);
}
void check_freopen_1(void) {
FILE *f1 = freopen("foo.c", "r", (FILE *)0); f1 = freopen(0, "w", (FILE *)0x123456); }
void check_freopen_2(void) {
FILE *f1 = fopen("foo.c", "r");
if (f1) {
FILE *f2 = freopen(0, "w", f1);
if (f2) {
fclose(f1);
fclose(f2); } else {
rewind(f1); rewind(f2);
}
}
}
void check_freopen_3(void) {
FILE *f1 = fopen("foo.c", "r");
if (f1) {
freopen(0, "w", f1);
rewind(f1); fclose(f1);
}
}
extern FILE *GlobalF;
extern void takeFile(FILE *);
void check_escape1(void) {
FILE *F = tmpfile();
if (!F)
return;
fwrite("1", 1, 1, F); GlobalF = F;
fwrite("1", 1, 1, F); }
void check_escape2(void) {
FILE *F = tmpfile();
if (!F)
return;
fwrite("1", 1, 1, F); takeFile(F);
fwrite("1", 1, 1, F); }
void check_escape3(void) {
FILE *F = tmpfile();
if (!F)
return;
takeFile(F);
F = freopen(0, "w", F);
if (!F)
return;
fwrite("1", 1, 1, F); fwrite("1", 1, 1, F); }
void check_escape4(void) {
FILE *F = tmpfile();
if (!F)
return;
fwrite("1", 1, 1, F);
fprintf(F, "0");
fwrite("1", 1, 1, F); fclose(F);
}
int Test;
_Noreturn void handle_error(void);
void check_leak_noreturn_1(void) {
FILE *F1 = tmpfile();
if (!F1)
return;
if (Test == 1) {
handle_error(); }
rewind(F1);
}
void check_leak_noreturn_2(void) {
FILE *F1 = tmpfile();
if (!F1)
return;
if (Test == 1) {
return; }
rewind(F1);
}