Merge "recovery: Switch to clang"
diff --git a/Android.mk b/Android.mk
index 3bcbeab..cfe3030 100644
--- a/Android.mk
+++ b/Android.mk
@@ -14,11 +14,10 @@
 
 LOCAL_PATH := $(call my-dir)
 
-
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES := fuse_sideload.c
-
+LOCAL_CLANG := true
 LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter
 LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE
 
@@ -54,6 +53,7 @@
 RECOVERY_FSTAB_VERSION := 2
 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION)
 LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CLANG := true
 
 LOCAL_C_INCLUDES += \
     system/vold \
@@ -97,6 +97,7 @@
 
 # All the APIs for testing
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
 LOCAL_MODULE := libverifier
 LOCAL_MODULE_TAGS := tests
 LOCAL_SRC_FILES := \
@@ -104,6 +105,7 @@
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
 LOCAL_MODULE := verifier_test
 LOCAL_FORCE_STATIC_EXECUTABLE := true
 LOCAL_MODULE_TAGS := tests
diff --git a/adb_install.cpp b/adb_install.cpp
index e3b94ea..4cfcb2a 100644
--- a/adb_install.cpp
+++ b/adb_install.cpp
@@ -91,7 +91,7 @@
     // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the host
     // connects and starts serving a package.  Poll for its
     // appearance.  (Note that inotify doesn't work with FUSE.)
-    int result;
+    int result = INSTALL_ERROR;
     int status;
     bool waited = false;
     struct stat st;
diff --git a/applypatch/Android.mk b/applypatch/Android.mk
index 861edd2..eb3e458 100644
--- a/applypatch/Android.mk
+++ b/applypatch/Android.mk
@@ -13,8 +13,10 @@
 # limitations under the License.
 
 LOCAL_PATH := $(call my-dir)
+
 include $(CLEAR_VARS)
 
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := applypatch.c bspatch.c freecache.c imgpatch.c utils.c
 LOCAL_MODULE := libapplypatch
 LOCAL_MODULE_TAGS := eng
@@ -25,6 +27,7 @@
 
 include $(CLEAR_VARS)
 
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := main.c
 LOCAL_MODULE := applypatch
 LOCAL_C_INCLUDES += bootable/recovery
@@ -35,6 +38,7 @@
 
 include $(CLEAR_VARS)
 
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := main.c
 LOCAL_MODULE := applypatch_static
 LOCAL_FORCE_STATIC_EXECUTABLE := true
@@ -47,6 +51,7 @@
 
 include $(CLEAR_VARS)
 
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := imgdiff.c utils.c bsdiff.c
 LOCAL_MODULE := imgdiff
 LOCAL_FORCE_STATIC_EXECUTABLE := true
diff --git a/edify/Android.mk b/edify/Android.mk
index 03c04e4..c366450 100644
--- a/edify/Android.mk
+++ b/edify/Android.mk
@@ -25,6 +25,7 @@
 LOCAL_MODULE := edify
 LOCAL_YACCFLAGS := -v
 LOCAL_CFLAGS += -Wno-unused-parameter
+LOCAL_CLANG := true
 
 include $(BUILD_HOST_EXECUTABLE)
 
@@ -38,5 +39,6 @@
 LOCAL_CFLAGS := $(edify_cflags)
 LOCAL_CFLAGS += -Wno-unused-parameter
 LOCAL_MODULE := libedify
+LOCAL_CLANG := true
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/minadbd/Android.mk b/minadbd/Android.mk
index a7a3e08..3db3b41 100644
--- a/minadbd/Android.mk
+++ b/minadbd/Android.mk
@@ -15,6 +15,7 @@
     fuse_adb_provider.cpp \
     services.cpp \
 
+LOCAL_CLANG := true
 LOCAL_MODULE := libminadbd
 LOCAL_CFLAGS := $(minadbd_cflags)
 LOCAL_CONLY_FLAGS := -Wimplicit-function-declaration
diff --git a/minui/Android.mk b/minui/Android.mk
index 52f0662..5584612 100644
--- a/minui/Android.mk
+++ b/minui/Android.mk
@@ -39,6 +39,7 @@
 
 # Used by OEMs for factory test images.
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
 LOCAL_MODULE := libminui
 LOCAL_WHOLE_STATIC_LIBRARIES += libminui
 LOCAL_SHARED_LIBRARIES := libpng
diff --git a/minzip/Android.mk b/minzip/Android.mk
index 045f355..48d26bc 100644
--- a/minzip/Android.mk
+++ b/minzip/Android.mk
@@ -16,6 +16,8 @@
 
 LOCAL_MODULE := libminzip
 
+LOCAL_CLANG := true
+
 LOCAL_CFLAGS += -Wall
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/minzip/Zip.c b/minzip/Zip.c
index 40712e0..a64c833 100644
--- a/minzip/Zip.c
+++ b/minzip/Zip.c
@@ -506,7 +506,6 @@
     void *cookie)
 {
     long result = -1;
-    unsigned char readBuf[32 * 1024];
     unsigned char procBuf[32 * 1024];
     z_stream zstream;
     int zerr;
@@ -603,7 +602,6 @@
     void *cookie)
 {
     bool ret = false;
-    off_t oldOff;
 
     switch (pEntry->compression) {
     case STORED:
diff --git a/mtdutils/Android.mk b/mtdutils/Android.mk
index f04355b..b7d35c2 100644
--- a/mtdutils/Android.mk
+++ b/mtdutils/Android.mk
@@ -6,10 +6,12 @@
 	mounts.c
 
 LOCAL_MODULE := libmtdutils
+LOCAL_CLANG := true
 
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
 LOCAL_SRC_FILES := flash_image.c
 LOCAL_MODULE := flash_image
 LOCAL_MODULE_TAGS := eng
diff --git a/recovery.cpp b/recovery.cpp
index bfc6895..76149cd 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -326,14 +326,18 @@
     ensure_path_mounted(LAST_KMSG_FILE);
 
     for (int i = max-1; i >= 0; --i) {
-        std::string old_log = android::base::StringPrintf((i == 0) ? "%s" : "%s.%d",
-                LAST_LOG_FILE, i);
+        std::string old_log = android::base::StringPrintf("%s", LAST_LOG_FILE);
+        if (i > 0) {
+          old_log += "." + std::to_string(i);
+        }
         std::string new_log = android::base::StringPrintf("%s.%d", LAST_LOG_FILE, i+1);
         // Ignore errors if old_log doesn't exist.
         rename(old_log.c_str(), new_log.c_str());
 
-        std::string old_kmsg = android::base::StringPrintf((i == 0) ? "%s" : "%s.%d",
-                LAST_KMSG_FILE, i);
+        std::string old_kmsg = android::base::StringPrintf("%s", LAST_KMSG_FILE);
+        if (i > 0) {
+          old_kmsg += "." + std::to_string(i);
+        }
         std::string new_kmsg = android::base::StringPrintf("%s.%d", LAST_KMSG_FILE, i+1);
         rename(old_kmsg.c_str(), new_kmsg.c_str());
     }
@@ -711,7 +715,10 @@
     // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x
     for (int i = 0; i < KEEP_LOG_COUNT; i++) {
         char* log_file;
-        if (asprintf(&log_file, (i == 0) ? "%s" : "%s.%d", LAST_LOG_FILE, i) == -1) {
+        int ret;
+        ret = (i == 0) ? asprintf(&log_file, "%s", LAST_LOG_FILE) :
+                asprintf(&log_file, "%s.%d", LAST_LOG_FILE, i);
+        if (ret == -1) {
             // memory allocation failure - return early. Should never happen.
             return;
         }
@@ -722,7 +729,9 @@
         }
 
         char* kmsg_file;
-        if (asprintf(&kmsg_file, (i == 0) ? "%s" : "%s.%d", LAST_KMSG_FILE, i) == -1) {
+        ret = (i == 0) ? asprintf(&kmsg_file, "%s", LAST_KMSG_FILE) :
+                asprintf(&kmsg_file, "%s.%d", LAST_KMSG_FILE, i);
+        if (ret == -1) {
             // memory allocation failure - return early. Should never happen.
             return;
         }
diff --git a/tests/Android.mk b/tests/Android.mk
index 02a272a..4ce00b4 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -17,6 +17,7 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
+LOCAL_CLANG := true
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 LOCAL_STATIC_LIBRARIES := libverifier
 LOCAL_SRC_FILES := asn1_decoder_test.cpp
diff --git a/uncrypt/Android.mk b/uncrypt/Android.mk
index d832d97..6859e75 100644
--- a/uncrypt/Android.mk
+++ b/uncrypt/Android.mk
@@ -16,6 +16,8 @@
 
 include $(CLEAR_VARS)
 
+LOCAL_CLANG := true
+
 LOCAL_SRC_FILES := uncrypt.cpp
 
 LOCAL_MODULE := uncrypt
diff --git a/updater/Android.mk b/updater/Android.mk
index 57f43da..a0ea06f 100644
--- a/updater/Android.mk
+++ b/updater/Android.mk
@@ -17,6 +17,8 @@
 # needed only for OTA packages.)
 LOCAL_MODULE_TAGS := eng
 
+LOCAL_CLANG := true
+
 LOCAL_SRC_FILES := $(updater_src_files)
 
 ifeq ($(TARGET_USERIMAGES_USE_EXT4), true)