summaryrefslogtreecommitdiffstats
path: root/libutils
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2014-06-04 18:29:49 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-06-04 18:29:49 +0000
commitc9573e147e20e941410693c83e42544dc2709444 (patch)
treee2bfb7ad9e80f6c17818f91bded03e37a316d54e /libutils
parentcc29030cc9c58697d1b75c1518274e34f0bb99e5 (diff)
parentb2a9129e8f0666884dee660515c51d4dd5c17c7a (diff)
downloadsystem_core-c9573e147e20e941410693c83e42544dc2709444.zip
system_core-c9573e147e20e941410693c83e42544dc2709444.tar.gz
system_core-c9573e147e20e941410693c83e42544dc2709444.tar.bz2
am b2a9129e: am bf0ed824: am 60ca7a22: Merge "libutils: turn on -Werror"
* commit 'b2a9129e8f0666884dee660515c51d4dd5c17c7a': libutils: turn on -Werror
Diffstat (limited to 'libutils')
-rw-r--r--libutils/Android.mk6
-rw-r--r--libutils/BlobCache.cpp4
-rw-r--r--libutils/FileMap.cpp10
-rw-r--r--libutils/LinearAllocator.cpp4
-rw-r--r--libutils/RefBase.cpp28
-rw-r--r--libutils/StopWatch.cpp2
-rw-r--r--libutils/String16.cpp2
-rw-r--r--libutils/String8.cpp1
-rw-r--r--libutils/SystemClock.cpp16
-rw-r--r--libutils/Threads.cpp30
-rw-r--r--libutils/Timers.cpp7
-rw-r--r--libutils/Unicode.cpp2
-rw-r--r--libutils/tests/BlobCache_test.cpp28
13 files changed, 80 insertions, 60 deletions
diff --git a/libutils/Android.mk b/libutils/Android.mk
index 1fef049..8ff0884 100644
--- a/libutils/Android.mk
+++ b/libutils/Android.mk
@@ -44,7 +44,7 @@ commonSources:= \
VectorImpl.cpp \
misc.cpp
-host_commonCflags := -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
+host_commonCflags := -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -Werror
ifeq ($(HOST_OS),windows)
ifeq ($(strip $(USE_CYGWIN),),)
@@ -100,6 +100,7 @@ LOCAL_SRC_FILES:= \
ifeq ($(TARGET_ARCH),mips)
LOCAL_CFLAGS += -DALIGN_DOUBLE
endif
+LOCAL_CFLAGS += -Werror
LOCAL_C_INCLUDES += \
bionic/libc/private \
@@ -127,7 +128,8 @@ LOCAL_SHARED_LIBRARIES := \
libbacktrace \
libcutils \
libdl \
- liblog \
+ liblog
+LOCAL_CFLAGS := -Werror
include external/stlport/libstlport.mk
diff --git a/libutils/BlobCache.cpp b/libutils/BlobCache.cpp
index 660917b..f00bf14 100644
--- a/libutils/BlobCache.cpp
+++ b/libutils/BlobCache.cpp
@@ -28,7 +28,7 @@
namespace android {
// BlobCache::Header::mMagicNumber value
-static const uint32_t blobCacheMagic = '_Bb$';
+static const uint32_t blobCacheMagic = ('_' << 24) + ('B' << 16) + ('b' << 8) + '$';
// BlobCache::Header::mBlobCacheVersion value
static const uint32_t blobCacheVersion = 1;
@@ -49,7 +49,7 @@ BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize
mRandState[1] = (now >> 16) & 0xFFFF;
mRandState[2] = (now >> 32) & 0xFFFF;
#endif
- ALOGV("initializing random seed using %lld", now);
+ ALOGV("initializing random seed using %lld", (unsigned long long)now);
}
void BlobCache::set(const void* key, size_t keySize, const void* value,
diff --git a/libutils/FileMap.cpp b/libutils/FileMap.cpp
index 933e7aa..be4b14f 100644
--- a/libutils/FileMap.cpp
+++ b/libutils/FileMap.cpp
@@ -23,7 +23,13 @@
#include <utils/FileMap.h>
#include <utils/Log.h>
+#if defined(HAVE_WIN32_FILEMAP) && !defined(__USE_MINGW_ANSI_STDIO)
+# define PRId32 "I32d"
+# define PRIx32 "I32x"
+# define PRId64 "I64d"
+#else
#include <inttypes.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
@@ -169,8 +175,8 @@ try_again:
goto try_again;
}
- ALOGE("mmap(%" PRId64 ",%zu) failed: %s\n",
- adjOffset, adjLength, strerror(errno));
+ ALOGE("mmap(%lld,%zu) failed: %s\n",
+ (long long)adjOffset, adjLength, strerror(errno));
return false;
}
mBasePtr = ptr;
diff --git a/libutils/LinearAllocator.cpp b/libutils/LinearAllocator.cpp
index a07a291..8b90696 100644
--- a/libutils/LinearAllocator.cpp
+++ b/libutils/LinearAllocator.cpp
@@ -92,7 +92,7 @@ public:
: mNextPage(0)
{}
- void* operator new(size_t size, void* buf) { return buf; }
+ void* operator new(size_t /*size*/, void* buf) { return buf; }
void* start() {
return (void*) (((size_t)this) + sizeof(Page));
@@ -103,7 +103,7 @@ public:
}
private:
- Page(const Page& other) {}
+ Page(const Page& /*other*/) {}
Page* mNextPage;
};
diff --git a/libutils/RefBase.cpp b/libutils/RefBase.cpp
index 385c226..02907ad 100644
--- a/libutils/RefBase.cpp
+++ b/libutils/RefBase.cpp
@@ -17,6 +17,14 @@
#define LOG_TAG "RefBase"
// #define LOG_NDEBUG 0
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <typeinfo>
+#include <unistd.h>
+
#include <utils/RefBase.h>
#include <utils/Atomic.h>
@@ -24,13 +32,9 @@
#include <utils/Log.h>
#include <utils/threads.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <typeinfo>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+#ifndef __unused
+#define __unused __attribute__((__unused__))
+#endif
// compile with refcounting debugging enabled
#define DEBUG_REFS 0
@@ -388,7 +392,7 @@ void RefBase::weakref_type::incWeak(const void* id)
{
weakref_impl* const impl = static_cast<weakref_impl*>(this);
impl->addWeakRef(id);
- const int32_t c = android_atomic_inc(&impl->mWeak);
+ const int32_t c __unused = android_atomic_inc(&impl->mWeak);
ALOG_ASSERT(c >= 0, "incWeak called on %p after last weak ref", this);
}
@@ -615,7 +619,7 @@ void RefBase::onLastStrongRef(const void* /*id*/)
{
}
-bool RefBase::onIncStrongAttempted(uint32_t flags, const void* id)
+bool RefBase::onIncStrongAttempted(uint32_t flags, const void* /*id*/)
{
return (flags&FIRST_INC_STRONG) ? true : false;
}
@@ -626,13 +630,15 @@ void RefBase::onLastWeakRef(const void* /*id*/)
// ---------------------------------------------------------------------------
-void RefBase::renameRefs(size_t n, const ReferenceRenamer& renamer) {
#if DEBUG_REFS
+void RefBase::renameRefs(size_t n, const ReferenceRenamer& renamer) {
for (size_t i=0 ; i<n ; i++) {
renamer(i);
}
-#endif
}
+#else
+void RefBase::renameRefs(size_t /*n*/, const ReferenceRenamer& /*renamer*/) { }
+#endif
void RefBase::renameRefId(weakref_type* ref,
const void* old_id, const void* new_id) {
diff --git a/libutils/StopWatch.cpp b/libutils/StopWatch.cpp
index b1708d6..8c7b596 100644
--- a/libutils/StopWatch.cpp
+++ b/libutils/StopWatch.cpp
@@ -21,7 +21,9 @@
#include <stdio.h>
/* for PRId64 */
+#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS 1
+#endif
#include <inttypes.h>
#include <utils/Log.h>
diff --git a/libutils/String16.cpp b/libutils/String16.cpp
index 3bdc349..91efdaa 100644
--- a/libutils/String16.cpp
+++ b/libutils/String16.cpp
@@ -66,8 +66,6 @@ static char16_t* allocFromUTF8(const char* u8str, size_t u8len)
return getEmptyString();
}
- const uint8_t* const u8end = u8cur + u8len;
-
SharedBuffer* buf = SharedBuffer::alloc(sizeof(char16_t)*(u16len+1));
if (buf) {
u8cur = (const uint8_t*) u8str;
diff --git a/libutils/String8.cpp b/libutils/String8.cpp
index 8acb4d4..49340bb 100644
--- a/libutils/String8.cpp
+++ b/libutils/String8.cpp
@@ -551,7 +551,6 @@ char* String8::find_extension(void) const
{
const char* lastSlash;
const char* lastDot;
- int extLen;
const char* const str = mString;
// only look at the filename
diff --git a/libutils/SystemClock.cpp b/libutils/SystemClock.cpp
index 413250f..dbad581 100644
--- a/libutils/SystemClock.cpp
+++ b/libutils/SystemClock.cpp
@@ -68,13 +68,7 @@ int64_t elapsedRealtime()
*/
#define DEBUG_TIMESTAMP 0
-static const char *gettime_method_names[] = {
- "clock_gettime",
- "ioctl",
- "systemTime",
-};
-
-#if DEBUG_TIMESTAMP
+#if DEBUG_TIMESTAMP && defined(ARCH_ARM)
static inline void checkTimeStamps(int64_t timestamp,
int64_t volatile *prevTimestampPtr,
int volatile *prevMethodPtr,
@@ -85,11 +79,16 @@ static inline void checkTimeStamps(int64_t timestamp,
* gettid, and int64_t is different on the ARM platform
* (ie long vs long long).
*/
-#ifdef ARCH_ARM
int64_t prevTimestamp = *prevTimestampPtr;
int prevMethod = *prevMethodPtr;
if (timestamp < prevTimestamp) {
+ static const char *gettime_method_names[] = {
+ "clock_gettime",
+ "ioctl",
+ "systemTime",
+ };
+
ALOGW("time going backwards: prev %lld(%s) vs now %lld(%s), tid=%d",
prevTimestamp, gettime_method_names[prevMethod],
timestamp, gettime_method_names[curMethod],
@@ -99,7 +98,6 @@ static inline void checkTimeStamps(int64_t timestamp,
// write is interrupted or not observed as a whole.
*prevTimestampPtr = timestamp;
*prevMethodPtr = curMethod;
-#endif
}
#else
#define checkTimeStamps(timestamp, prevTimestampPtr, prevMethodPtr, curMethod)
diff --git a/libutils/Threads.cpp b/libutils/Threads.cpp
index ff74914..cc7fe89 100644
--- a/libutils/Threads.cpp
+++ b/libutils/Threads.cpp
@@ -17,16 +17,11 @@
// #define LOG_NDEBUG 0
#define LOG_TAG "libutils.threads"
-#include <utils/threads.h>
-#include <utils/Log.h>
-
-#include <cutils/sched_policy.h>
-
+#include <assert.h>
+#include <errno.h>
+#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
-#include <memory.h>
-#include <errno.h>
-#include <assert.h>
#include <unistd.h>
#if defined(HAVE_PTHREADS)
@@ -47,6 +42,17 @@
#include <sys/prctl.h>
#endif
+#include <utils/threads.h>
+#include <utils/Log.h>
+
+#include <cutils/sched_policy.h>
+
+#ifdef HAVE_ANDROID_OS
+# define __android_unused
+#else
+# define __android_unused __attribute__((__unused__))
+#endif
+
/*
* ===========================================================================
* Thread wrappers
@@ -119,7 +125,7 @@ void androidSetThreadName(const char* name) {
int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
void *userData,
- const char* threadName,
+ const char* threadName __android_unused,
int32_t threadPriority,
size_t threadStackSize,
android_thread_id_t *threadId)
@@ -251,9 +257,9 @@ static bool doCreateThread(android_thread_func_t fn, void* arg, android_thread_i
int androidCreateRawThreadEtc(android_thread_func_t fn,
void *userData,
- const char* threadName,
- int32_t threadPriority,
- size_t threadStackSize,
+ const char* /*threadName*/,
+ int32_t /*threadPriority*/,
+ size_t /*threadStackSize*/,
android_thread_id_t *threadId)
{
return doCreateThread( fn, userData, threadId);
diff --git a/libutils/Timers.cpp b/libutils/Timers.cpp
index a431e92..4687d4d 100644
--- a/libutils/Timers.cpp
+++ b/libutils/Timers.cpp
@@ -32,9 +32,9 @@
#include <windows.h>
#endif
+#if defined(HAVE_ANDROID_OS)
nsecs_t systemTime(int clock)
{
-#if defined(HAVE_ANDROID_OS)
static const clockid_t clocks[] = {
CLOCK_REALTIME,
CLOCK_MONOTONIC,
@@ -46,7 +46,10 @@ nsecs_t systemTime(int clock)
t.tv_sec = t.tv_nsec = 0;
clock_gettime(clocks[clock], &t);
return nsecs_t(t.tv_sec)*1000000000LL + t.tv_nsec;
+}
#else
+nsecs_t systemTime(int /*clock*/)
+{
// Clock support varies widely across hosts. Mac OS doesn't support
// posix clocks, older glibcs don't support CLOCK_BOOTTIME and Windows
// is windows.
@@ -54,8 +57,8 @@ nsecs_t systemTime(int clock)
t.tv_sec = t.tv_usec = 0;
gettimeofday(&t, NULL);
return nsecs_t(t.tv_sec)*1000000000LL + nsecs_t(t.tv_usec)*1000LL;
-#endif
}
+#endif
int toMillisecondTimeoutDelay(nsecs_t referenceTime, nsecs_t timeoutTime)
{
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index a66e3bb..fe8887d 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -576,7 +576,7 @@ void utf8_to_utf16(const uint8_t* u8str, size_t u8len, char16_t* u16str) {
char16_t* utf8_to_utf16_n(const uint8_t* src, size_t srcLen, char16_t* dst, size_t dstLen) {
const uint8_t* const u8end = src + srcLen;
const uint8_t* u8cur = src;
- const uint16_t* const u16end = dst + dstLen;
+ const char16_t* const u16end = dst + dstLen;
char16_t* u16cur = dst;
while (u8cur < u8end && u16cur < u16end) {
diff --git a/libutils/tests/BlobCache_test.cpp b/libutils/tests/BlobCache_test.cpp
index 7202123..dac4e2c 100644
--- a/libutils/tests/BlobCache_test.cpp
+++ b/libutils/tests/BlobCache_test.cpp
@@ -44,7 +44,7 @@ protected:
};
TEST_F(BlobCacheTest, CacheSingleValueSucceeds) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));
ASSERT_EQ('e', buf[0]);
@@ -54,7 +54,7 @@ TEST_F(BlobCacheTest, CacheSingleValueSucceeds) {
}
TEST_F(BlobCacheTest, CacheTwoValuesSucceeds) {
- char buf[2] = { 0xee, 0xee };
+ unsigned char buf[2] = { 0xee, 0xee };
mBC->set("ab", 2, "cd", 2);
mBC->set("ef", 2, "gh", 2);
ASSERT_EQ(size_t(2), mBC->get("ab", 2, buf, 2));
@@ -66,7 +66,7 @@ TEST_F(BlobCacheTest, CacheTwoValuesSucceeds) {
}
TEST_F(BlobCacheTest, GetOnlyWritesInsideBounds) {
- char buf[6] = { 0xee, 0xee, 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[6] = { 0xee, 0xee, 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf+1, 4));
ASSERT_EQ(0xee, buf[0]);
@@ -78,7 +78,7 @@ TEST_F(BlobCacheTest, GetOnlyWritesInsideBounds) {
}
TEST_F(BlobCacheTest, GetOnlyWritesIfBufferIsLargeEnough) {
- char buf[3] = { 0xee, 0xee, 0xee };
+ unsigned char buf[3] = { 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 3));
ASSERT_EQ(0xee, buf[0]);
@@ -92,7 +92,7 @@ TEST_F(BlobCacheTest, GetDoesntAccessNullBuffer) {
}
TEST_F(BlobCacheTest, MultipleSetsCacheLatestValue) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
mBC->set("abcd", 4, "ijkl", 4);
ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));
@@ -103,7 +103,7 @@ TEST_F(BlobCacheTest, MultipleSetsCacheLatestValue) {
}
TEST_F(BlobCacheTest, SecondSetKeepsFirstValueIfTooLarge) {
- char buf[MAX_VALUE_SIZE+1] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[MAX_VALUE_SIZE+1] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
mBC->set("abcd", 4, buf, MAX_VALUE_SIZE+1);
ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));
@@ -115,7 +115,7 @@ TEST_F(BlobCacheTest, SecondSetKeepsFirstValueIfTooLarge) {
TEST_F(BlobCacheTest, DoesntCacheIfKeyIsTooBig) {
char key[MAX_KEY_SIZE+1];
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
for (int i = 0; i < MAX_KEY_SIZE+1; i++) {
key[i] = 'a';
}
@@ -165,7 +165,7 @@ TEST_F(BlobCacheTest, DoesntCacheIfKeyValuePairIsTooBig) {
TEST_F(BlobCacheTest, CacheMaxKeySizeSucceeds) {
char key[MAX_KEY_SIZE];
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
for (int i = 0; i < MAX_KEY_SIZE; i++) {
key[i] = 'a';
}
@@ -214,7 +214,7 @@ TEST_F(BlobCacheTest, CacheMaxKeyValuePairSizeSucceeds) {
}
TEST_F(BlobCacheTest, CacheMinKeyAndValueSizeSucceeds) {
- char buf[1] = { 0xee };
+ unsigned char buf[1] = { 0xee };
mBC->set("x", 1, "y", 1);
ASSERT_EQ(size_t(1), mBC->get("x", 1, buf, 1));
ASSERT_EQ('y', buf[0]);
@@ -282,7 +282,7 @@ protected:
};
TEST_F(BlobCacheFlattenTest, FlattenOneValue) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
roundTrip();
ASSERT_EQ(size_t(4), mBC2->get("abcd", 4, buf, 4));
@@ -348,7 +348,7 @@ TEST_F(BlobCacheFlattenTest, FlattenCatchesBufferTooSmall) {
}
TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadMagic) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
size_t size = mBC->getFlattenedSize();
@@ -365,7 +365,7 @@ TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadMagic) {
}
TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheVersion) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
size_t size = mBC->getFlattenedSize();
@@ -384,7 +384,7 @@ TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheVersion) {
}
TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheDeviceVersion) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
size_t size = mBC->getFlattenedSize();
@@ -403,7 +403,7 @@ TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheDeviceVersion) {
}
TEST_F(BlobCacheFlattenTest, UnflattenCatchesBufferTooSmall) {
- char buf[4] = { 0xee, 0xee, 0xee, 0xee };
+ unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee };
mBC->set("abcd", 4, "efgh", 4);
size_t size = mBC->getFlattenedSize();