From c217373bd69c501e5ad30d72df1893ab81c7fd66 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 13 May 2015 13:18:04 -0700 Subject: [PATCH] Fix unused result errors in bionic. This lets us use _FORTIFY_SOURCE=2 on the host. Change-Id: I69f5ff9834bfd595aae6584104bee10c4d8a5eeb --- benchmarks/stdio_benchmark.cpp | 3 ++- benchmarks/utils.cpp | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp index 342e56154af..69e01a99601 100644 --- a/benchmarks/stdio_benchmark.cpp +++ b/benchmarks/stdio_benchmark.cpp @@ -16,6 +16,7 @@ #include #include +#include #include @@ -73,7 +74,7 @@ static void FopenFgetsFclose(int iters, bool no_locking) { for (int i = 0; i < iters; ++i) { FILE* fp = fopen("/proc/version", "re"); if (no_locking) __fsetlocking(fp, FSETLOCKING_BYCALLER); - fgets(buf, sizeof(buf), fp); + if (fgets(buf, sizeof(buf), fp) == nullptr) abort(); fclose(fp); } } diff --git a/benchmarks/utils.cpp b/benchmarks/utils.cpp index 863b9db136a..cf17edb3f35 100644 --- a/benchmarks/utils.cpp +++ b/benchmarks/utils.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "utils.h" + #include #include #include @@ -21,7 +23,7 @@ #include -#include "utils.h" +#include int Round(int n) { int base = 1; @@ -72,10 +74,7 @@ std::string PrettyInt(long value, size_t base) { break; } } - char* s = NULL; - asprintf(&s, "%s%" PRId64 "%s", (negative_number ? "-" : ""), - count / kAmountPerUnit[i], kUnitStrings[i]); - std::string result(s); - free(s); - return result; + return android::base::StringPrintf("%s%" PRId64 "%s", + negative_number ? "-" : "", + count / kAmountPerUnit[i], kUnitStrings[i]); }