Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c6c7f0b authored by Colin Cross's avatar Colin Cross
Browse files

Fix warnings in libziparchive

system/core/include is included in the global include path using
-isystem, which hides all warnings.  zlib.h is included through
system/core/include/ziparchive/zip_archive.h, which was hiding warnings
in it.  Use a #pragma around the call to deflateInit2, it is a macro
that expands to an old-style cast, in preparation for moving from
-isystem to -I.  Also move the ZipString constructor to zip_archive.cc
so it can assert on the length of the string parameter and fix an
implicit conversion from size_t to uint16_t.

Test: m -j native
Bug: 31492149
Change-Id: I74cdad7fe9c723859b5cfbea73c8f27d9d9ca265
parent 36b88ce9
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -43,8 +43,7 @@ struct ZipString {
  /*
   * entry_name has to be an c-style string with only ASCII characters.
   */
  explicit ZipString(const char* entry_name)
      : name(reinterpret_cast<const uint8_t*>(entry_name)), name_length(strlen(entry_name)) {}
  explicit ZipString(const char* entry_name);

  bool operator==(const ZipString& rhs) const {
    return name && (name_length == rhs.name_length) &&
+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include <vector>

#include "android-base/file.h"
#include "android-base/logging.h"
#include "android-base/macros.h"  // TEMP_FAILURE_RETRY may or may not be in unistd
#include "android-base/memory.h"
#include "log/log.h"
@@ -1073,3 +1074,10 @@ const char* ErrorCodeString(int32_t error_code) {
int GetFileDescriptor(const ZipArchiveHandle handle) {
  return reinterpret_cast<ZipArchive*>(handle)->fd;
}

ZipString::ZipString(const char* entry_name)
    : name(reinterpret_cast<const uint8_t*>(entry_name)) {
  size_t len = strlen(entry_name);
  CHECK_LE(len, static_cast<size_t>(UINT16_MAX));
  name_length = static_cast<uint16_t>(len);
}
+4 −0
Original line number Diff line number Diff line
@@ -243,8 +243,12 @@ int32_t ZipWriter::PrepareDeflate() {
  // Initialize the z_stream for compression.
  z_stream_ = std::unique_ptr<z_stream, void(*)(z_stream*)>(new z_stream(), DeleteZStream);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
  int zerr = deflateInit2(z_stream_.get(), Z_BEST_COMPRESSION, Z_DEFLATED, -MAX_WBITS,
                          DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
#pragma GCC diagnostic pop

  if (zerr != Z_OK) {
    if (zerr == Z_VERSION_ERROR) {
      ALOGE("Installed zlib is not compatible with linked version (%s)", ZLIB_VERSION);