#include "Inputs/system-header-simulator.h"
void clang_analyzer_eval(int);
void clang_analyzer_warnIfReached(void);
void StreamTesterChecker_make_feof_stream(FILE *);
void StreamTesterChecker_make_ferror_stream(FILE *);
void error_fopen(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); fclose(F);
}
void error_freopen(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
F = freopen(0, "w", F);
if (!F)
return;
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); fclose(F);
}
void stream_error_feof(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
StreamTesterChecker_make_feof_stream(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); clearerr(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); fclose(F);
}
void stream_error_ferror(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
StreamTesterChecker_make_ferror_stream(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); clearerr(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); fclose(F);
}
void error_fread(void) {
FILE *F = tmpfile();
if (!F)
return;
char Buf[10];
int Ret = fread(Buf, 1, 10, F);
if (Ret == 10) {
clang_analyzer_eval(feof(F) || ferror(F)); } else {
clang_analyzer_eval(feof(F) || ferror(F)); if (feof(F)) {
clang_analyzer_warnIfReached(); fread(Buf, 1, 10, F); clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); }
if (ferror(F)) {
clang_analyzer_warnIfReached(); fread(Buf, 1, 10, F); }
}
fclose(F);
Ret = fread(Buf, 1, 10, F); }
void error_fwrite(void) {
FILE *F = tmpfile();
if (!F)
return;
const char *Buf = "123456789";
int Ret = fwrite(Buf, 1, 10, F);
if (Ret == 10) {
clang_analyzer_eval(feof(F) || ferror(F)); } else {
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); fwrite(0, 1, 10, F); }
fclose(F);
Ret = fwrite(0, 1, 10, F); }
void freadwrite_zerosize(FILE *F) {
fwrite(0, 1, 0, F);
fwrite(0, 0, 1, F);
fread(0, 1, 0, F);
fread(0, 0, 1, F);
}
void freadwrite_zerosize_eofstate(FILE *F) {
fwrite(0, 1, 0, F);
fwrite(0, 0, 1, F);
fread(0, 1, 0, F); fread(0, 0, 1, F); }
void error_fread_fwrite_zerosize(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
freadwrite_zerosize(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F));
StreamTesterChecker_make_ferror_stream(F);
freadwrite_zerosize(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F));
StreamTesterChecker_make_feof_stream(F);
freadwrite_zerosize_eofstate(F);
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F));
fclose(F);
}
void error_fseek(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
int rc = fseek(F, 0, SEEK_SET);
if (rc) {
int IsFEof = feof(F), IsFError = ferror(F);
clang_analyzer_eval(IsFEof || IsFError);
clang_analyzer_eval(IsFEof && IsFError); if (IsFEof)
clang_analyzer_eval(feof(F)); else
clang_analyzer_eval(feof(F)); if (IsFError)
clang_analyzer_eval(ferror(F)); else
clang_analyzer_eval(ferror(F)); } else {
clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); clang_analyzer_eval(feof(F)); clang_analyzer_eval(ferror(F)); }
fclose(F);
}
void error_indeterminate(void) {
FILE *F = fopen("file", "r+");
if (!F)
return;
const char *Buf = "123456789";
int rc = fseek(F, 0, SEEK_SET);
if (rc) {
if (feof(F)) {
fwrite(Buf, 1, 10, F); } else if (ferror(F)) {
fwrite(Buf, 1, 10, F); } else {
fwrite(Buf, 1, 10, F); }
}
fclose(F);
}
void error_indeterminate_clearerr(void) {
FILE *F = fopen("file", "r+");
if (!F)
return;
const char *Buf = "123456789";
int rc = fseek(F, 0, SEEK_SET);
if (rc) {
if (feof(F)) {
clearerr(F);
fwrite(Buf, 1, 10, F); } else if (ferror(F)) {
clearerr(F);
fwrite(Buf, 1, 10, F); } else {
clearerr(F);
fwrite(Buf, 1, 10, F); }
}
fclose(F);
}
void error_indeterminate_feof1(void) {
FILE *F = fopen("file", "r+");
if (!F)
return;
char Buf[10];
if (fread(Buf, 1, 10, F) < 10) {
if (feof(F)) {
fwrite("1", 1, 1, F); }
}
fclose(F);
}
void error_indeterminate_feof2(void) {
FILE *F = fopen("file", "r+");
if (!F)
return;
char Buf[10];
if (fread(Buf, 1, 10, F) < 10) {
if (ferror(F) == 0) {
fwrite("1", 1, 1, F); }
}
fclose(F);
}