Skip to content

Commit

Permalink
Fix a warning about comparing signed and unsigned values
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 190977545
  • Loading branch information
cushon authored and Copybara-Service committed Mar 29, 2018
1 parent a76f7db commit a29da01
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions third_party/ijar/mapped_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class MappedOutputFile {
const char* errmsg_;
bool opened_;
u1* buffer_;
u8 estimated_size_;
size_t estimated_size_;

public:
MappedOutputFile(const char* name, u8 estimated_size);
MappedOutputFile(const char* name, size_t estimated_size);
virtual ~MappedOutputFile();

// If opening the file succeeded or not.
Expand All @@ -76,7 +76,7 @@ class MappedOutputFile {

// The mapped contents of the file.
u1* Buffer() const { return buffer_; }
int Close(int size);
int Close(size_t size);
};

} // namespace devtools_ijar
Expand Down
8 changes: 4 additions & 4 deletions third_party/ijar/mapped_file_unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct MappedOutputFileImpl {
int mmap_length_;
};

MappedOutputFile::MappedOutputFile(const char* name, u8 estimated_size)
MappedOutputFile::MappedOutputFile(const char* name, size_t estimated_size)
: estimated_size_(estimated_size) {
impl_ = NULL;
opened_ = false;
Expand All @@ -111,7 +111,7 @@ MappedOutputFile::MappedOutputFile(const char* name, u8 estimated_size)
// Ensure that any buffer overflow in JarStripper will result in
// SIGSEGV or SIGBUS by over-allocating beyond the end of the file.
size_t mmap_length = std::min(estimated_size + sysconf(_SC_PAGESIZE),
(u8) std::numeric_limits<size_t>::max());
std::numeric_limits<size_t>::max());
void* mapped = mmap(NULL, mmap_length, PROT_WRITE, MAP_SHARED, fd, 0);
if (mapped == MAP_FAILED) {
snprintf(errmsg, MAX_ERROR, "mmap(): %s", strerror(errno));
Expand All @@ -131,9 +131,9 @@ MappedOutputFile::~MappedOutputFile() {
delete impl_;
}

int MappedOutputFile::Close(int size) {
int MappedOutputFile::Close(size_t size) {
if (size > estimated_size_) {
snprintf(errmsg, MAX_ERROR, "size %d > estimated size %lld", size,
snprintf(errmsg, MAX_ERROR, "size %zu > estimated size %zu", size,
estimated_size_);
errmsg_ = errmsg;
return -1;
Expand Down
4 changes: 2 additions & 2 deletions third_party/ijar/mapped_file_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ struct MappedOutputFileImpl {
}
};

MappedOutputFile::MappedOutputFile(const char* name, u8 estimated_size) {
MappedOutputFile::MappedOutputFile(const char* name, size_t estimated_size) {
impl_ = NULL;
opened_ = false;
errmsg_ = errmsg;
Expand Down Expand Up @@ -169,7 +169,7 @@ MappedOutputFile::~MappedOutputFile() {
delete impl_;
}

int MappedOutputFile::Close(int size) {
int MappedOutputFile::Close(size_t size) {
if (!UnmapViewOfFile(buffer_)) {
blaze_util::die(255, "MappedOutputFile::Close: UnmapViewOfFile failed: %s",
blaze_util::GetLastErrorString().c_str());
Expand Down
20 changes: 10 additions & 10 deletions third_party/ijar/zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
namespace devtools_ijar {
// In the absence of ZIP64 support, zip files are limited to 4GB.
// http://www.info-zip.org/FAQ.html#limits
static const u8 kMaximumOutputSize = std::numeric_limits<uint32_t>::max();
static const size_t kMaximumOutputSize = std::numeric_limits<uint32_t>::max();

static const u4 kDefaultTimestamp =
30 << 25 | 1 << 21 | 1 << 16; // January 1, 2010 in DOS time
Expand Down Expand Up @@ -199,11 +199,11 @@ class InputZipFile : public ZipExtractor {
//
class OutputZipFile : public ZipBuilder {
public:
OutputZipFile(const char* filename, u8 estimated_size) :
output_file_(NULL),
filename_(filename),
estimated_size_(estimated_size),
finished_(false) {
OutputZipFile(const char *filename, size_t estimated_size)
: output_file_(NULL),
filename_(filename),
estimated_size_(estimated_size),
finished_(false) {
errmsg[0] = 0;
}

Expand Down Expand Up @@ -257,7 +257,7 @@ class OutputZipFile : public ZipBuilder {

MappedOutputFile* output_file_;
const char* filename_;
u8 estimated_size_;
size_t estimated_size_;
bool finished_;

// OutputZipFile is responsible for maintaining the following
Expand Down Expand Up @@ -1078,8 +1078,8 @@ int OutputZipFile::FinishFile(size_t filelength, bool compress,
bool OutputZipFile::Open() {
if (estimated_size_ > kMaximumOutputSize) {
fprintf(stderr,
"Uncompressed input jar has size %llu, "
"which exceeds the maximum supported output size %llu.\n"
"Uncompressed input jar has size %lu, "
"which exceeds the maximum supported output size %lu.\n"
"Assuming that ijar will be smaller and hoping for the best.\n",
estimated_size_, kMaximumOutputSize);
estimated_size_ = kMaximumOutputSize;
Expand All @@ -1099,7 +1099,7 @@ bool OutputZipFile::Open() {
return true;
}

ZipBuilder* ZipBuilder::Create(const char* zip_file, u8 estimated_size) {
ZipBuilder *ZipBuilder::Create(const char *zip_file, size_t estimated_size) {
OutputZipFile* result = new OutputZipFile(zip_file, estimated_size);
if (!result->Open()) {
fprintf(stderr, "%s\n", result->GetError());
Expand Down
2 changes: 1 addition & 1 deletion third_party/ijar/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ZipBuilder {
// ZipExtractor::CalculateOuputLength() to have an estimated_size depending on
// a list of file to store.
// On failure, returns NULL. Refer to errno for error code.
static ZipBuilder* Create(const char* zip_file, u8 estimated_size);
static ZipBuilder* Create(const char* zip_file, size_t estimated_size);

// Estimate the maximum size of the ZIP files containing files in the "files"
// null-terminated array.
Expand Down

0 comments on commit a29da01

Please sign in to comment.