Merge "libutils: turn on -Werror"

This commit is contained in:
Mark Salyzyn 2014-06-04 17:55:05 +00:00 committed by Gerrit Code Review
commit 60ca7a2223
13 changed files with 80 additions and 60 deletions

View file

@ -43,7 +43,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),),)
@ -99,6 +99,7 @@ LOCAL_SRC_FILES:= \
ifeq ($(TARGET_ARCH),mips)
LOCAL_CFLAGS += -DALIGN_DOUBLE
endif
LOCAL_CFLAGS += -Werror
LOCAL_C_INCLUDES += \
bionic/libc/private \
@ -126,7 +127,8 @@ LOCAL_SHARED_LIBRARIES := \
libbacktrace \
libcutils \
libdl \
liblog \
liblog
LOCAL_CFLAGS := -Werror
include external/stlport/libstlport.mk

View file

@ -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,

View file

@ -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;

View file

@ -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;
};

View file

@ -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) {

View file

@ -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>

View file

@ -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;

View file

@ -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

View file

@ -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)

View file

@ -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);

View file

@ -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)
{

View file

@ -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) {

View file

@ -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();