am d7156748: am f61eec3e: am 2bdac629: Merge changes Ic769eafc,I63f28b3b

* commit 'd715674899b9026ce5f5c653dc218fc7b67f9c7b':
  updater: Use android::base::ParseInt() to parse integers.
  Suppress some compiler warnings due to signedness.
diff --git a/mtdutils/mtdutils.c b/mtdutils/mtdutils.c
index cc30334..cd4f52c 100644
--- a/mtdutils/mtdutils.c
+++ b/mtdutils/mtdutils.c
@@ -300,20 +300,20 @@
         if (TEMP_FAILURE_RETRY(lseek64(fd, pos, SEEK_SET)) != pos ||
                     TEMP_FAILURE_RETRY(read(fd, data, size)) != size) {
             printf("mtd: read error at 0x%08llx (%s)\n",
-                    pos, strerror(errno));
+                   (long long)pos, strerror(errno));
         } else if (ioctl(fd, ECCGETSTATS, &after)) {
             printf("mtd: ECCGETSTATS error (%s)\n", strerror(errno));
             return -1;
         } else if (after.failed != before.failed) {
             printf("mtd: ECC errors (%d soft, %d hard) at 0x%08llx\n",
-                    after.corrected - before.corrected,
-                    after.failed - before.failed, pos);
+                   after.corrected - before.corrected,
+                   after.failed - before.failed, (long long)pos);
             // copy the comparison baseline for the next read.
             memcpy(&before, &after, sizeof(struct mtd_ecc_stats));
         } else if ((mgbb = ioctl(fd, MEMGETBADBLOCK, &pos))) {
             fprintf(stderr,
                     "mtd: MEMGETBADBLOCK returned %d at 0x%08llx: %s\n",
-                    mgbb, pos, strerror(errno));
+                    mgbb, (long long)pos, strerror(errno));
         } else {
             return 0;  // Success!
         }
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 6111d0d..ddb474f 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -36,6 +36,7 @@
 #include <string>
 #include <vector>
 
+#include <base/parseint.h>
 #include <base/strings.h>
 
 #include "applypatch/applypatch.h"
@@ -77,40 +78,31 @@
         goto err;
     }
 
-    errno = 0;
-    val = strtol(pieces[0].c_str(), nullptr, 0);
-
-    if (errno != 0 || val < 2 || val > INT_MAX) {
-        goto err;
-    } else if (val % 2) {
-        goto err; // must be even
-    } else if (val != static_cast<long int>(pieces.size() - 1)) {
+    size_t num;
+    if (!android::base::ParseUint(pieces[0].c_str(), &num, static_cast<size_t>(INT_MAX))) {
         goto err;
     }
 
-    size_t num;
-    num = static_cast<size_t>(val);
+    if (num == 0 || num % 2) {
+        goto err; // must be even
+    } else if (num != pieces.size() - 1) {
+        goto err;
+    }
 
     rs.pos.resize(num);
     rs.count = num / 2;
     rs.size = 0;
 
     for (size_t i = 0; i < num; i += 2) {
-        const char* token = pieces[i+1].c_str();
-        errno = 0;
-        val = strtol(token, nullptr, 0);
-        if (errno != 0 || val < 0 || val > INT_MAX) {
+        if (!android::base::ParseUint(pieces[i+1].c_str(), &rs.pos[i],
+                                      static_cast<size_t>(INT_MAX))) {
             goto err;
         }
-        rs.pos[i] = static_cast<size_t>(val);
 
-        token = pieces[i+2].c_str();
-        errno = 0;
-        val = strtol(token, nullptr, 0);
-        if (errno != 0 || val < 0 || val > INT_MAX) {
+        if (!android::base::ParseUint(pieces[i+2].c_str(), &rs.pos[i+1],
+                                      static_cast<size_t>(INT_MAX))) {
             goto err;
         }
-        rs.pos[i+1] = static_cast<size_t>(val);
 
         if (rs.pos[i] >= rs.pos[i+1]) {
             goto err; // empty or negative range
@@ -800,7 +792,7 @@
 
     // <src_block_count>
     word = strtok_r(nullptr, " ", wordsave);
-    src_blocks = strtol(word, nullptr, 0);
+    android::base::ParseUint(word, &src_blocks);
 
     allocate(src_blocks * BLOCKSIZE, buffer);
 
@@ -1381,24 +1373,21 @@
     std::vector<std::string> lines = android::base::Split(transfer_list, "\n");
 
     // First line in transfer list is the version number
-    long int val;
-    errno = 0;
-    val = strtol(lines[0].c_str(), nullptr, 0);
-    if (errno != 0 || val < 1 || val > 3) {
+    if (!android::base::ParseInt(lines[0].c_str(), &params.version, 1, 3)) {
         fprintf(stderr, "unexpected transfer list version [%s]\n", lines[0].c_str());
         return StringValue(strdup(""));
     }
-    params.version = static_cast<int>(val);
 
     fprintf(stderr, "blockimg version is %d\n", params.version);
 
     // Second line in transfer list is the total number of blocks we expect to write
-    int total_blocks = strtol(lines[1].c_str(), nullptr, 0);
-
-    if (total_blocks < 0) {
+    int total_blocks;
+    if (!android::base::ParseInt(lines[1].c_str(), &total_blocks, 0)) {
         ErrorAbort(state, "unexpected block count [%s]\n", lines[1].c_str());
         return StringValue(strdup(""));
-    } else if (total_blocks == 0) {
+    }
+
+    if (total_blocks == 0) {
         return StringValue(strdup("t"));
     }
 
@@ -1408,24 +1397,20 @@
         fprintf(stderr, "maximum stash entries %s\n", lines[2].c_str());
 
         // Fourth line is the maximum number of blocks that will be stashed simultaneously
-        int stash_max_blocks = strtol(lines[3].c_str(), nullptr, 0);
-
-        if (stash_max_blocks < 0) {
+        int stash_max_blocks;
+        if (!android::base::ParseInt(lines[3].c_str(), &stash_max_blocks, 0)) {
             ErrorAbort(state, "unexpected maximum stash blocks [%s]\n", lines[3].c_str());
             return StringValue(strdup(""));
         }
 
-        if (stash_max_blocks >= 0) {
-            int res = CreateStash(state, stash_max_blocks, blockdev_filename->data,
-                    params.stashbase);
+        int res = CreateStash(state, stash_max_blocks, blockdev_filename->data, params.stashbase);
 
-            if (res == -1) {
-                return StringValue(strdup(""));
-            }
-
-            params.createdstash = res;
+        if (res == -1) {
+            return StringValue(strdup(""));
         }
 
+        params.createdstash = res;
+
         start += 2;
     }
 
diff --git a/updater/install.cpp b/updater/install.cpp
index a6ed078..97e3905 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -34,6 +34,7 @@
 #include <linux/xattr.h>
 #include <inttypes.h>
 
+#include <base/parseint.h>
 #include <base/strings.h>
 #include <base/stringprintf.h>
 
@@ -474,7 +475,8 @@
     }
 
     double frac = strtod(frac_str, NULL);
-    int sec = strtol(sec_str, NULL, 10);
+    int sec;
+    android::base::ParseInt(sec_str, &sec);
 
     UpdaterInfo* ui = (UpdaterInfo*)(state->cookie);
     fprintf(ui->cmd_pipe, "progress %f %d\n", frac, sec);
@@ -990,7 +992,7 @@
         goto done;
     }
 
-    if (fread(buffer, 1, st.st_size, f) != st.st_size) {
+    if (fread(buffer, 1, st.st_size, f) != static_cast<size_t>(st.st_size)) {
         ErrorAbort(state, "%s: failed to read %lld bytes from %s",
                    name, (long long)st.st_size+1, filename);
         fclose(f);
@@ -1145,12 +1147,11 @@
         return NULL;
     }
 
-    char* endptr;
-    size_t bytes = strtol(bytes_str, &endptr, 10);
-    if (bytes == 0 && endptr == bytes_str) {
+    size_t bytes;
+    if (!android::base::ParseUint(bytes_str, &bytes)) {
         ErrorAbort(state, "%s(): can't parse \"%s\" as byte count\n\n", name, bytes_str);
         free(bytes_str);
-        return NULL;
+        return nullptr;
     }
 
     return StringValue(strdup(CacheSizeCheck(bytes) ? "" : "t"));
@@ -1174,16 +1175,14 @@
         return NULL;
     }
 
-    char* endptr;
-    size_t target_size = strtol(target_size_str, &endptr, 10);
-    if (target_size == 0 && endptr == target_size_str) {
-        ErrorAbort(state, "%s(): can't parse \"%s\" as byte count",
-                   name, target_size_str);
+    size_t target_size;
+    if (!android::base::ParseUint(target_size_str, &target_size)) {
+        ErrorAbort(state, "%s(): can't parse \"%s\" as byte count", name, target_size_str);
         free(source_filename);
         free(target_filename);
         free(target_sha1);
         free(target_size_str);
-        return NULL;
+        return nullptr;
     }
 
     int patchcount = (argc-4) / 2;
@@ -1523,7 +1522,8 @@
     char* len_str;
     if (ReadArgs(state, argv, 2, &filename, &len_str) < 0) return NULL;
 
-    size_t len = strtoull(len_str, NULL, 0);
+    size_t len;
+    android::base::ParseUint(len_str, &len);
     int fd = open(filename, O_WRONLY, 0644);
     int success = wipe_block_device(fd, len);