From 8fef4591be761b4ffe37830404cf93f47e998179 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Wed, 20 Dec 2023 11:19:42 -0800 Subject: Fix -Wshorten-64-to-32 warning on Android NDK when targeting x86 stat.h defines struct stat to use long long on Android NDK when targeting x86; off_t however is defined as long, which is 32-bit (unlike other Unix-like platforms). This results in a narrowing conversion which produces a warning, and can also result in silently reading a prefix of a huge file instead of a clean "out of memory" error. There's no way for us to preserve the type exactly but always widening to long long should be safe; get_file_size will proceed to check if length actually fits into size_t which is what we ultimately need, and that overflow check will fail on files that are >4 GB in size. --- src/pugixml.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index fe91d24..b48cedd 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -4801,7 +4801,8 @@ PUGI_IMPL_NS_BEGIN // anything that's not a regular file doesn't have a coherent length if (!S_ISREG(st.st_mode)) return status_io_error; - typedef off_t length_type; + // normally st_size is off_t, but Android NDK defines off_t as long (which is 32-bit when targeting x86 on Android) and st_size as long long + typedef long long length_type; length_type length = st.st_size; #elif defined(PUGI_IMPL_MSVC_CRT_VERSION) && PUGI_IMPL_MSVC_CRT_VERSION >= 1400 // there are 64-bit versions of fseek/ftell, let's use them -- cgit v1.1