aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2023-12-20 11:19:42 -0800
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2023-12-20 11:19:42 -0800
commit8fef4591be761b4ffe37830404cf93f47e998179 (patch)
tree0edecc925b46634366a90a4e460949fe069484ba
parent499750ad95899814500711776b57e3fabf800daa (diff)
downloadpugixml-8fef4591be761b4ffe37830404cf93f47e998179.zip
pugixml-8fef4591be761b4ffe37830404cf93f47e998179.tar.gz
pugixml-8fef4591be761b4ffe37830404cf93f47e998179.tar.bz2
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.
-rw-r--r--src/pugixml.cpp3
1 files changed, 2 insertions, 1 deletions
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