From 12717169a51335f4b20b7c78a63b9ab66a81a366 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 29 Apr 2014 15:49:14 -0700 Subject: [PATCH] libcutils: turn on -Werror - Deal with some -Wunused / -Wunused-variable issues Change-Id: I28c23fb213382a392ec30935749fb359e072d664 --- libcutils/Android.mk | 12 ++++++------ libcutils/ashmem-host.c | 26 ++++++++++++++------------ libcutils/cpu_info.c | 9 ++++----- libcutils/dlmalloc_stubs.c | 10 ++++++---- libcutils/iosched_policy.c | 16 +++++++++------- libcutils/partition_utils.c | 9 +++++---- libcutils/process_name.c | 18 ++++++++++-------- libcutils/qtaguid.c | 7 ++----- libcutils/sched_policy.c | 21 +++++++++++---------- libcutils/socket_inaddr_any_server.c | 12 +++++------- libcutils/socket_local_client.c | 9 ++++----- libcutils/socket_loopback_client.c | 12 +++++------- libcutils/socket_loopback_server.c | 12 +++++------- libcutils/socket_network_client.c | 11 ++++------- libcutils/sockets.c | 7 +++++-- libcutils/str_parms.c | 5 +---- libcutils/threads.c | 6 ++---- libcutils/trace.c | 3 +-- 18 files changed, 99 insertions(+), 106 deletions(-) diff --git a/libcutils/Android.mk b/libcutils/Android.mk index 635695ab5..405761cff 100644 --- a/libcutils/Android.mk +++ b/libcutils/Android.mk @@ -77,7 +77,7 @@ LOCAL_MODULE := libcutils LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c LOCAL_LDLIBS := -lpthread LOCAL_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS += $(hostSmpFlag) +LOCAL_CFLAGS += $(hostSmpFlag) -Werror include $(BUILD_HOST_STATIC_LIBRARY) @@ -88,14 +88,14 @@ LOCAL_MODULE := lib64cutils LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c LOCAL_LDLIBS := -lpthread LOCAL_STATIC_LIBRARIES := lib64log -LOCAL_CFLAGS += $(hostSmpFlag) -m64 +LOCAL_CFLAGS += $(hostSmpFlag) -m64 -Werror include $(BUILD_HOST_STATIC_LIBRARY) # Tests for host # ======================================================== include $(CLEAR_VARS) LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS +LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c LOCAL_STATIC_LIBRARIES := liblog LOCAL_MODULE_TAGS := optional @@ -135,7 +135,7 @@ endif # !arm LOCAL_C_INCLUDES := $(libcutils_c_includes) LOCAL_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS += $(targetSmpFlag) +LOCAL_CFLAGS += $(targetSmpFlag) -Werror include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -144,13 +144,13 @@ LOCAL_MODULE := libcutils # liblog symbols present in libcutils. LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog LOCAL_SHARED_LIBRARIES := liblog -LOCAL_CFLAGS += $(targetSmpFlag) +LOCAL_CFLAGS += $(targetSmpFlag) -Werror LOCAL_C_INCLUDES := $(libcutils_c_includes) include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := tst_str_parms -LOCAL_CFLAGS += -DTEST_STR_PARMS +LOCAL_CFLAGS += -DTEST_STR_PARMS -Werror LOCAL_SRC_FILES := str_parms.c hashmap.c memory.c LOCAL_SHARED_LIBRARIES := liblog LOCAL_MODULE_TAGS := optional diff --git a/libcutils/ashmem-host.c b/libcutils/ashmem-host.c index f03e13037..cfb5d66f0 100644 --- a/libcutils/ashmem-host.c +++ b/libcutils/ashmem-host.c @@ -19,20 +19,22 @@ * an ashmem-enabled kernel. See ashmem-dev.c for the real ashmem-based version. */ -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include #include -int ashmem_create_region(const char *ignored, size_t size) +#define __unused __attribute__((__unused__)) + +int ashmem_create_region(const char *ignored __unused, size_t size) { static const char txt[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -78,17 +80,17 @@ error: return -1; } -int ashmem_set_prot_region(int fd, int prot) +int ashmem_set_prot_region(int fd __unused, int prot __unused) { return 0; } -int ashmem_pin_region(int fd, size_t offset, size_t len) +int ashmem_pin_region(int fd __unused, size_t offset __unused, size_t len __unused) { return ASHMEM_NOT_PURGED; } -int ashmem_unpin_region(int fd, size_t offset, size_t len) +int ashmem_unpin_region(int fd __unused, size_t offset __unused, size_t len __unused) { return ASHMEM_IS_UNPINNED; } diff --git a/libcutils/cpu_info.c b/libcutils/cpu_info.c index 23dda8aa1..21fa1dc70 100644 --- a/libcutils/cpu_info.c +++ b/libcutils/cpu_info.c @@ -1,5 +1,4 @@ -/* libs/cutils/cpu_info.c -** +/* ** Copyright 2007, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,11 +14,12 @@ ** limitations under the License. */ -#include -#include #include +#include #include +#include + // we cache the serial number here. // this is also used as a fgets() line buffer when we are reading /proc/cpuinfo static char serial_number[100] = { 0 }; @@ -31,7 +31,6 @@ extern const char* get_cpu_serial_number(void) FILE* file; char* chp, *end; char* whitespace; - int length; // read serial number from /proc/cpuinfo file = fopen("proc/cpuinfo", "r"); diff --git a/libcutils/dlmalloc_stubs.c b/libcutils/dlmalloc_stubs.c index c327a55a7..6dca911b3 100644 --- a/libcutils/dlmalloc_stubs.c +++ b/libcutils/dlmalloc_stubs.c @@ -15,20 +15,22 @@ */ #include "../../../bionic/libc/bionic/dlmalloc.h" -#include "cutils/log.h" +#include "log/log.h" + +#define UNUSED __attribute__((__unused__)) /* * Stubs for functions defined in bionic/libc/bionic/dlmalloc.c. These * are used in host builds, as the host libc will not contain these * functions. */ -void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*), - void* arg) +void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*) UNUSED, + void* arg UNUSED) { ALOGW("Called host unimplemented stub: dlmalloc_inspect_all"); } -int dlmalloc_trim(size_t unused) +int dlmalloc_trim(size_t unused UNUSED) { ALOGW("Called host unimplemented stub: dlmalloc_trim"); return 0; diff --git a/libcutils/iosched_policy.c b/libcutils/iosched_policy.c index 5d90a01e7..67e101dec 100644 --- a/libcutils/iosched_policy.c +++ b/libcutils/iosched_policy.c @@ -1,5 +1,4 @@ /* -** ** Copyright 2007-2014, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,12 +14,12 @@ ** limitations under the License. */ -#include -#include -#include -#include #include #include +#include +#include +#include +#include #ifdef HAVE_SCHED_H @@ -30,6 +29,9 @@ /* #include */ extern int ioprio_set(int which, int who, int ioprio); extern int ioprio_get(int which, int who); +#define __android_unused +#else +#define __android_unused __attribute__((__unused__)) #endif enum { @@ -41,7 +43,7 @@ enum { #define CLASS_SHIFT 13 #define IOPRIO_NORM 4 -int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio) { +int android_set_ioprio(int pid __android_unused, IoSchedClass clazz __android_unused, int ioprio __android_unused) { #ifdef HAVE_ANDROID_OS if (ioprio_set(WHO_PROCESS, pid, ioprio | (clazz << CLASS_SHIFT))) { return -1; @@ -50,7 +52,7 @@ int android_set_ioprio(int pid, IoSchedClass clazz, int ioprio) { return 0; } -int android_get_ioprio(int pid, IoSchedClass *clazz, int *ioprio) { +int android_get_ioprio(int pid __android_unused, IoSchedClass *clazz, int *ioprio) { #ifdef HAVE_ANDROID_OS int rc; diff --git a/libcutils/partition_utils.c b/libcutils/partition_utils.c index 10539fa59..823b16289 100644 --- a/libcutils/partition_utils.c +++ b/libcutils/partition_utils.c @@ -14,12 +14,13 @@ * limitations under the License. */ -#include -#include #include -#include #include #include /* for BLKGETSIZE */ +#include +#include +#include + #include static int only_one_char(char *buf, int len, char c) @@ -39,7 +40,7 @@ static int only_one_char(char *buf, int len, char c) int partition_wiped(char *source) { char buf[4096]; - int fd, ret, wiped; + int fd, ret; if ((fd = open(source, O_RDONLY)) < 0) { return 0; diff --git a/libcutils/process_name.c b/libcutils/process_name.c index a6ab951b7..9c3dfb8d2 100644 --- a/libcutils/process_name.c +++ b/libcutils/process_name.c @@ -14,25 +14,27 @@ * limitations under the License. */ +#include #include #include +#if defined(HAVE_PRCTL) +#include +#endif +#include +#include +#include + #include #ifdef HAVE_ANDROID_OS #include #endif -#include -#include -#include -#include - -#if defined(HAVE_PRCTL) -#include -#endif #define PROCESS_NAME_DEVICE "/sys/qemu_trace/process_name" static const char* process_name = "unknown"; +#ifdef HAVE_ANDROID_OS static int running_in_emulator = -1; +#endif void set_process_name(const char* new_name) { #ifdef HAVE_ANDROID_OS diff --git a/libcutils/qtaguid.c b/libcutils/qtaguid.c index 899a7b44f..00e211c77 100644 --- a/libcutils/qtaguid.c +++ b/libcutils/qtaguid.c @@ -1,5 +1,4 @@ -/* libcutils/qtaguid.c -** +/* ** Copyright 2011, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -146,7 +145,7 @@ int qtaguid_setCounterSet(int counterSetNum, uid_t uid) { int qtaguid_deleteTagData(int tag, uid_t uid) { char lineBuf[CTRL_MAX_INPUT_LEN]; - int fd, cnt = 0, res = 0; + int cnt = 0, res = 0; uint64_t kTag = (uint64_t)tag << 32; ALOGV("Deleting tag data with tag %" PRIx64 "{%d,0} for uid %d", kTag, tag, uid); @@ -164,8 +163,6 @@ int qtaguid_deleteTagData(int tag, uid_t uid) { } int qtaguid_setPacifier(int on) { - int param_fd; - int res; const char *value; value = on ? "Y" : "N"; diff --git a/libcutils/sched_policy.c b/libcutils/sched_policy.c index d20d217b7..9f092d6b3 100644 --- a/libcutils/sched_policy.c +++ b/libcutils/sched_policy.c @@ -1,6 +1,4 @@ - -/* libs/cutils/sched_policy.c -** +/* ** Copyright 2007, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,14 +16,17 @@ #define LOG_TAG "SchedPolicy" -#include -#include -#include -#include #include #include +#include +#include +#include +#include + #include -#include +#include + +#define UNUSED __attribute__((__unused__)) /* Re-map SP_DEFAULT to the system default policy, and leave other values unchanged. * Call this any place a SchedPolicy is used as an input parameter. @@ -331,12 +332,12 @@ int set_sched_policy(int tid, SchedPolicy policy) /* Stubs for non-Android targets. */ -int set_sched_policy(int tid, SchedPolicy policy) +int set_sched_policy(int tid UNUSED, SchedPolicy policy UNUSED) { return 0; } -int get_sched_policy(int tid, SchedPolicy *policy) +int get_sched_policy(int tid UNUSED, SchedPolicy *policy) { *policy = SP_SYSTEM_DEFAULT; return 0; diff --git a/libcutils/socket_inaddr_any_server.c b/libcutils/socket_inaddr_any_server.c index 7d5dab4c8..f70d56b21 100644 --- a/libcutils/socket_inaddr_any_server.c +++ b/libcutils/socket_inaddr_any_server.c @@ -1,5 +1,4 @@ -/* libs/cutils/socket_inaddr_any_server.c -** +/* ** Copyright 2006, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,13 +14,11 @@ ** limitations under the License. */ -#include - +#include +#include #include #include #include -#include -#include #ifndef HAVE_WINSOCK #include @@ -30,13 +27,14 @@ #include #endif +#include + #define LISTEN_BACKLOG 4 /* open listen() port on any interface */ int socket_inaddr_any_server(int port, int type) { struct sockaddr_in addr; - size_t alen; int s, n; memset(&addr, 0, sizeof(addr)); diff --git a/libcutils/socket_local_client.c b/libcutils/socket_local_client.c index 531051674..ddcc2da4e 100644 --- a/libcutils/socket_local_client.c +++ b/libcutils/socket_local_client.c @@ -14,13 +14,13 @@ * limitations under the License. */ -#include - +#include +#include #include #include #include -#include -#include + +#include #ifdef HAVE_WINSOCK @@ -128,7 +128,6 @@ int socket_local_client_connect(int fd, const char *name, int namespaceId, { struct sockaddr_un addr; socklen_t alen; - size_t namelen; int err; err = socket_make_sockaddr_un(name, namespaceId, &addr, &alen); diff --git a/libcutils/socket_loopback_client.c b/libcutils/socket_loopback_client.c index cb82c5ede..9aed7b7ce 100644 --- a/libcutils/socket_loopback_client.c +++ b/libcutils/socket_loopback_client.c @@ -1,5 +1,4 @@ -/* libs/cutils/socket_loopback_client.c -** +/* ** Copyright 2006, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,13 +14,11 @@ ** limitations under the License. */ -#include - +#include +#include #include #include #include -#include -#include #ifndef HAVE_WINSOCK #include @@ -30,6 +27,8 @@ #include #endif +#include + /* Connect to port on the loopback IP interface. type is * SOCK_STREAM or SOCK_DGRAM. * return is a file descriptor or -1 on error @@ -37,7 +36,6 @@ int socket_loopback_client(int port, int type) { struct sockaddr_in addr; - socklen_t alen; int s; memset(&addr, 0, sizeof(addr)); diff --git a/libcutils/socket_loopback_server.c b/libcutils/socket_loopback_server.c index 3208488ad..5175e9cfe 100644 --- a/libcutils/socket_loopback_server.c +++ b/libcutils/socket_loopback_server.c @@ -1,5 +1,4 @@ -/* libs/cutils/socket_loopback_server.c -** +/* ** Copyright 2006, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,13 +14,11 @@ ** limitations under the License. */ -#include - +#include +#include #include #include #include -#include -#include #define LISTEN_BACKLOG 4 @@ -32,11 +29,12 @@ #include #endif +#include + /* open listen() port on loopback interface */ int socket_loopback_server(int port, int type) { struct sockaddr_in addr; - size_t alen; int s, n; memset(&addr, 0, sizeof(addr)); diff --git a/libcutils/socket_network_client.c b/libcutils/socket_network_client.c index a64006cdf..c52013dda 100644 --- a/libcutils/socket_network_client.c +++ b/libcutils/socket_network_client.c @@ -1,5 +1,4 @@ -/* libs/cutils/socket_network_client.c -** +/* ** Copyright 2006, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,13 +14,11 @@ ** limitations under the License. */ -#include - +#include +#include #include #include #include -#include -#include #ifndef HAVE_WINSOCK #include @@ -31,6 +28,7 @@ #include #endif +#include /* Connect to port on the IP interface. type is * SOCK_STREAM or SOCK_DGRAM. @@ -40,7 +38,6 @@ int socket_network_client(const char *host, int port, int type) { struct hostent *hp; struct sockaddr_in addr; - socklen_t alen; int s; hp = gethostbyname(host); diff --git a/libcutils/sockets.c b/libcutils/sockets.c index b5a1b3d47..15ede2b5b 100644 --- a/libcutils/sockets.c +++ b/libcutils/sockets.c @@ -14,15 +14,18 @@ * limitations under the License. */ -#include #include +#include #ifdef HAVE_ANDROID_OS /* For the socket trust (credentials) check */ #include +#define __android_unused +#else +#define __android_unused __attribute__((__unused__)) #endif -bool socket_peer_is_trusted(int fd) +bool socket_peer_is_trusted(int fd __android_unused) { #ifdef HAVE_ANDROID_OS struct ucred cr; diff --git a/libcutils/str_parms.c b/libcutils/str_parms.c index 953b91dbb..2e3ce9fd6 100644 --- a/libcutils/str_parms.c +++ b/libcutils/str_parms.c @@ -25,10 +25,9 @@ #include #include -#include #include - #include +#include #define UNUSED __attribute__((unused)) @@ -374,8 +373,6 @@ static void test_str_parms_str(const char *str) int main(void) { - struct str_parms *str_parms; - test_str_parms_str(""); test_str_parms_str(";"); test_str_parms_str("="); diff --git a/libcutils/threads.c b/libcutils/threads.c index 42cc92871..bf182f081 100644 --- a/libcutils/threads.c +++ b/libcutils/threads.c @@ -1,5 +1,4 @@ -/* libs/cutils/threads.c -** +/* ** Copyright (C) 2007, The Android Open Source Project ** ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,13 +13,12 @@ ** See the License for the specific language governing permissions and ** limitations under the License. */ + #include #ifdef HAVE_PTHREADS void* thread_store_get( thread_store_t* store ) { - const pthread_key_t k = store->tls; - if (!store->has_tls) return NULL; diff --git a/libcutils/trace.c b/libcutils/trace.c index 9754a44fa..f57aac2a1 100644 --- a/libcutils/trace.c +++ b/libcutils/trace.c @@ -28,7 +28,7 @@ #include #define LOG_TAG "cutils-trace" -#include +#include volatile int32_t atrace_is_ready = 0; int atrace_marker_fd = -1; @@ -86,7 +86,6 @@ static bool atrace_is_cmdline_match(const char* cmdline) static bool atrace_is_app_tracing_enabled() { bool sys_debuggable = false; - bool proc_debuggable = false; char value[PROPERTY_VALUE_MAX]; bool result = false;