1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-25 04:05:40 +03:00
aports/community/chromium/narrowing-cast.patch

26 lines
1 KiB
Diff

cl: https://chromium-review.googlesource.com/c/chromium/src/+/4159728
diff --git a/base/system/sys_info_posix.cc b/base/system/sys_info_posix.cc
index 92e70aa..80c750ba 100644
--- a/base/system/sys_info_posix.cc
+++ b/base/system/sys_info_posix.cc
@@ -67,10 +67,16 @@
if (HANDLE_EINTR(statfs(path.value().c_str(), &stats)) != 0)
return false;
- switch (stats.f_type) {
+ // This static_cast is here because various libcs disagree about the size
+ // and signedness of statfs::f_type. In particular, glibc has it as either a
+ // signed long or a signed int depending on platform, and other libcs
+ // (following the statfs(2) man page) use unsigned int instead. To avoid
+ // either an unsigned -> signed cast, or a narrowing cast, we always upcast
+ // statfs::f_type to unsigned long. :(
+ switch (static_cast<unsigned long>(stats.f_type)) {
case TMPFS_MAGIC:
- case static_cast<int>(HUGETLBFS_MAGIC):
- case static_cast<int>(RAMFS_MAGIC):
+ case HUGETLBFS_MAGIC:
+ case RAMFS_MAGIC:
return true;
}
return false;