summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-03-24 00:57:32 +0000
committerKostya Serebryany <kcc@google.com>2016-03-24 00:57:32 +0000
commit6278f933a87c40bcfd95e23c91574d9f245c0b5e (patch)
treea8231b1e2000dee688350887d57f998899ce94a9
parent8758c9ddadd3e78c07696033b5b7cb6b7417d144 (diff)
downloadbcm5719-llvm-6278f933a87c40bcfd95e23c91574d9f245c0b5e.tar.gz
bcm5719-llvm-6278f933a87c40bcfd95e23c91574d9f245c0b5e.zip
[libFuzzer] use fdopen+vfprintf instead of fsnprintf+write
llvm-svn: 264230
-rw-r--r--llvm/lib/Fuzzer/FuzzerIO.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.cpp b/llvm/lib/Fuzzer/FuzzerIO.cpp
index 358e645d728..de1624d70d4 100644
--- a/llvm/lib/Fuzzer/FuzzerIO.cpp
+++ b/llvm/lib/Fuzzer/FuzzerIO.cpp
@@ -20,7 +20,7 @@
namespace fuzzer {
-static int OutputFd = 2;
+static FILE *OutputFile = stderr;
bool IsFile(const std::string &Path) {
struct stat St;
@@ -117,24 +117,23 @@ std::string DirPlusFile(const std::string &DirPath,
}
void DupAndCloseStderr() {
- assert(OutputFd == 2);
- OutputFd = dup(OutputFd);
- if (OutputFd < 0)
- OutputFd = 2;
- else
- close(2);
+ int OutputFd = dup(2);
+ if (OutputFd > 0) {
+ FILE *NewOutputFile = fdopen(OutputFd, "w");
+ if (NewOutputFile) {
+ OutputFile = NewOutputFile;
+ close(2);
+ }
+ }
}
void CloseStdout() { close(1); }
void Printf(const char *Fmt, ...) {
- char Buf[1024];
va_list ap;
va_start(ap, Fmt);
- int Formatted = vsnprintf(Buf, sizeof(Buf), Fmt, ap);
+ vfprintf(OutputFile, Fmt, ap);
va_end(ap);
- if (Formatted)
- write(OutputFd, Buf, Formatted);
}
} // namespace fuzzer
OpenPOWER on IntegriCloud