aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-05-29 09:12:27 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-29 09:14:13 -0700
commitfa59fbf40a27e61b8def2ba0ce8bb3c0733070aa (patch)
treedb1ab40942ae28053bc1c0b2a1ce5905706ae8ba
parentbf1ac7e0a1371bb3325e6860acdf27b1f8bfa0d1 (diff)
Fixes Bazel build on Raspberry Pi 3 Raspbian GNU/Linux 9 (stetch). The portability bug is that sysconf() returns a long unsigned int but size_t is unsigned int (on the Pi 3) unsigned int causing a compilation failure (see below). Fixing the code to be portable, in this case, seems harmless in the common case where size_t is 64 bits AFAICT.
(I don't know your org so please feel free to reassign.) The compilation error I received is: ERROR: /home/hallorant/src/bazel-0.13.1/third_party/ijar/BUILD:10:1: C++ compilation of rule '//third_party/ijar:zip' failed (Exit 1): gcc failed: error executing command (cd /tmp/bazel_TMQ6Ae45/out/execroot/io_bazel && \ exec env - \ PWD=/proc/self/cwd \ /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++0x' -MD -MF bazel-out/host/bin/third_party/ijar/_objs/zip/third_party/ijar/mapped_file_unix.d '-frandom-seed=bazel-out/host/bin/third_party/ijar/_objs/zip/third_party/ijar/mapped_file_unix.o' -DBLAZE_OPENSOURCE -iquote . -iquote bazel-out/host/genfiles -iquote external/bazel_tools -iquote bazel-out/host/genfiles/external/bazel_tools -isystem third_party/zlib -isystem bazel-out/host/genfiles/third_party/zlib -isystem bazel-out/host/bin/third_party/zlib -g0 -g0 -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c third_party/ijar/mapped_file_unix.cc -o bazel-out/host/bin/third_party/ijar/_objs/zip/third_party/ijar/mapped_file_unix.o) third_party/ijar/mapped_file_unix.cc: In constructor 'devtools_ijar::MappedOutputFile::MappedOutputFile(const char*, size_t)': third_party/ijar/mapped_file_unix.cc:114:67: error: no matching function for call to 'min(long unsigned int, unsigned int)' std::numeric_limits<size_t>::max()); PiperOrigin-RevId: 198405201
-rw-r--r--third_party/ijar/mapped_file_unix.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/third_party/ijar/mapped_file_unix.cc b/third_party/ijar/mapped_file_unix.cc
index ced7d8726f..fbfca42723 100644
--- a/third_party/ijar/mapped_file_unix.cc
+++ b/third_party/ijar/mapped_file_unix.cc
@@ -110,8 +110,9 @@ MappedOutputFile::MappedOutputFile(const char* name, size_t 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),
- std::numeric_limits<size_t>::max());
+ size_t mmap_length =
+ std::min(static_cast<size_t>(estimated_size + sysconf(_SC_PAGESIZE)),
+ 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));