mgorny created this revision. mgorny added reviewers: krytarowski, vitalybuka. Herald added subscribers: Sanitizers, llvm-commits, dberris, kubamracek.
Add two new test cases that test the following stdio.h functions: - clearerr() - feof() - ferror() - fileno() - fgetc() - getc() - ungetc() Repository: rCRT Compiler Runtime https://reviews.llvm.org/D56136 Files: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <stdio.h> + +int main(int argc, char **argv) { + FILE *fp; + + fp = fopen(argv[0], "r"); + if (!fp) + return 1; + + if (fgetc(fp) == EOF) + return 2; + + if (ungetc('X', fp) == EOF) + return 3; + + if (getc(fp) != 'X') + return 4; + + fclose(fp); + return 0; +} Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc @@ -0,0 +1,51 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <stdio.h> +#include <unistd.h> + +int main(int argc, char **argv) { + FILE *fp; + int fd; + char buf[BUFSIZ]; + + fp = fopen(argv[0], "r"); + if (!fp) + return 1; + + // file should be good upon opening + if (feof(fp) || ferror(fp)) + return 2; + + // read until EOF + while (fread(buf, 1, sizeof buf, fp) != 0) {} + if (!feof(fp)) + return 3; + + // clear EOF + clearerr(fp); + if (feof(fp) || ferror(fp)) + return 4; + + // get file descriptor + fd = fileno(fp); + if (fd == -1) + return 5; + + // break the file by closing underlying descriptor + if (close(fd) == -1) + return 6; + + // verify that an error is signalled + if (fread(buf, 1, sizeof buf, fp) != 0) + return 7; + if (!ferror(fp)) + return 8; + + // clear error + clearerr(fp); + if (feof(fp) || ferror(fp)) + return 9; + + fclose(fp); + return 0; +}
Index: test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc @@ -0,0 +1,23 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <stdio.h> + +int main(int argc, char **argv) { + FILE *fp; + + fp = fopen(argv[0], "r"); + if (!fp) + return 1; + + if (fgetc(fp) == EOF) + return 2; + + if (ungetc('X', fp) == EOF) + return 3; + + if (getc(fp) != 'X') + return 4; + + fclose(fp); + return 0; +} Index: test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc @@ -0,0 +1,51 @@ +// RUN: %clangxx -g %s -o %t && %run %t + +#include <stdio.h> +#include <unistd.h> + +int main(int argc, char **argv) { + FILE *fp; + int fd; + char buf[BUFSIZ]; + + fp = fopen(argv[0], "r"); + if (!fp) + return 1; + + // file should be good upon opening + if (feof(fp) || ferror(fp)) + return 2; + + // read until EOF + while (fread(buf, 1, sizeof buf, fp) != 0) {} + if (!feof(fp)) + return 3; + + // clear EOF + clearerr(fp); + if (feof(fp) || ferror(fp)) + return 4; + + // get file descriptor + fd = fileno(fp); + if (fd == -1) + return 5; + + // break the file by closing underlying descriptor + if (close(fd) == -1) + return 6; + + // verify that an error is signalled + if (fread(buf, 1, sizeof buf, fp) != 0) + return 7; + if (!ferror(fp)) + return 8; + + // clear error + clearerr(fp); + if (feof(fp) || ferror(fp)) + return 9; + + fclose(fp); + return 0; +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits