Use explicitly sized types in zipalign/ziptime
getLongLE would return a 64-bit number with the upper 32-bits set when
decoding a 32-bit number with the top bit set. Per the zip file format,
it was only expected to return a 32-bit number. Use explicitly sized
types so that we use the proper sizes and don't do any implicit
extensions.
Change-Id: I5a4304dc99ce5f8f17284d4ca3094ae115207a1e
diff --git a/tools/ziptime/ZipFile.cpp b/tools/ziptime/ZipFile.cpp
index c4c898e..1d111af 100644
--- a/tools/ziptime/ZipFile.cpp
+++ b/tools/ziptime/ZipFile.cpp
@@ -24,6 +24,7 @@
#include <sys/stat.h>
#include <errno.h>
#include <assert.h>
+#include <inttypes.h>
using namespace android;
@@ -72,7 +73,7 @@
status_t ZipFile::rewriteCentralDir(void)
{
status_t result = 0;
- unsigned char* buf = NULL;
+ uint8_t* buf = NULL;
off_t fileLength, seekStart;
long readAmount;
int i;
@@ -88,7 +89,7 @@
goto bail;
}
- buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
+ buf = new uint8_t[EndOfCentralDir::kMaxEOCDSearch];
if (buf == NULL) {
LOG("Failure allocating %d bytes for EOCD search",
EndOfCentralDir::kMaxEOCDSearch);
@@ -152,7 +153,7 @@
* we're hoping to preserve.
*/
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
- LOG("Failure seeking to central dir offset %ld\n",
+ LOG("Failure seeking to central dir offset %" PRIu32 "\n",
mEOCD.mCentralDirOffset);
result = -1;
goto bail;
@@ -179,7 +180,7 @@
/*
* If all went well, we should now be back at the EOCD.
*/
- unsigned char checkBuf[4];
+ uint8_t checkBuf[4];
if (fread(checkBuf, 1, 4, mZipFp) != 4) {
LOG("EOCD check read failed\n");
result = -1;
@@ -208,9 +209,9 @@
* "buf" should be positioned at the EOCD signature, and should contain
* the entire EOCD area including the comment.
*/
-status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
+status_t ZipFile::EndOfCentralDir::readBuf(const uint8_t* buf, int len)
{
- unsigned short diskNumber, diskWithCentralDir, numEntries;
+ uint16_t diskNumber, diskWithCentralDir, numEntries;
if (len < kEOCDLen) {
/* looks like ZIP file got truncated */