From c8d31940985c83a54989afdc9e8e74af9417535a Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 3 Nov 2016 10:29:23 -0700 Subject: [PATCH] logd: switch to using arraysize() from libbase macros Test: logd-unit-tests, liblog-unit-tests & logcat-unit-tests Bug: 32450474 Change-Id: Iacdc4677f2c83898a7812c2af2c36e7ff7d92764 --- logd/LogAudit.cpp | 5 +++-- logd/tests/logd_test.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/logd/LogAudit.cpp b/logd/LogAudit.cpp index 3811daaa0..c3ccd840a 100644 --- a/logd/LogAudit.cpp +++ b/logd/LogAudit.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -143,7 +144,7 @@ int LogAudit::logPrint(const char *fmt, ...) { iov[2].iov_len = strlen(newline); } - writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0])); + writev(fdDmesg, iov, arraysize(iov)); free(last_str); last_str = NULL; } @@ -165,7 +166,7 @@ int LogAudit::logPrint(const char *fmt, ...) { iov[2].iov_base = const_cast(newline); iov[2].iov_len = strlen(newline); - writev(fdDmesg, iov, sizeof(iov) / sizeof(iov[0])); + writev(fdDmesg, iov, arraysize(iov)); } } diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp index e0a4cc34b..254a3f849 100644 --- a/logd/tests/logd_test.cpp +++ b/logd/tests/logd_test.cpp @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -351,7 +352,7 @@ TEST(logd, both) { "/dev/log/system", "/dev/log_system", }; - for (unsigned int i = 0; i < (sizeof(loggers) / sizeof(loggers[0])); ++i) { + for (unsigned int i = 0; i < arraysize(loggers); ++i) { fd = open(loggers[i], O_RDONLY); if (fd < 0) { continue; @@ -434,12 +435,12 @@ TEST(logd, benchmark) { static const unsigned int log_latency = 4; static const unsigned int log_delay = 5; - unsigned long ns[sizeof(benchmarks) / sizeof(benchmarks[0])]; + unsigned long ns[arraysize(benchmarks)]; memset(ns, 0, sizeof(ns)); while (fgets(buffer, sizeof(buffer), fp)) { - for (unsigned i = 0; i < sizeof(ns) / sizeof(ns[0]); ++i) { + for (unsigned i = 0; i < arraysize(ns); ++i) { char *cp = strstr(buffer, benchmarks[i]); if (!cp) { continue; @@ -470,7 +471,7 @@ TEST(logd, benchmark) { EXPECT_GE(20000000UL, ns[log_delay]); // 10500289 user - for (unsigned i = 0; i < sizeof(ns) / sizeof(ns[0]); ++i) { + for (unsigned i = 0; i < arraysize(ns); ++i) { EXPECT_NE(0UL, ns[i]); }