2015-06-22 13:18 GMT+03:00 David Faure <fa...@kde.org>: > I don't follow. How does 0x858458F6 not fit into an int, even on a 32 bit > machine? > OK, this is just about signed/unsigned, not about really wider. > So yeah the bug is that glibc should use unsigned int there instead, > but the issue you mention "the comparison will fail" might not happen, if the > comparison uses the right signedness. There is no truncation happening, at > least. > > A static_cast<unsigned int> workaround in kcoreaddons would work in practice, > no?
David, I believe in the same theory you described. I couldn't reproduce the error on clang x86_64, even though I tried hard. The most I could get is a warning "overflow converting case value to switch condition type (2240043254 to -2054924042)" when you change 0x858458F6 to 0x858458F6LL to make it be not convertible to a 4-byte signed int (see attached .cpp file.) The hack with static_cast<unsigned int>() helps here, but we need to use something more portable than "unsigned int", because on x86_64 sizeof(statfs.f_type) == 8, i.e. differs from unsigned int. -- Alexander Potashev
#include <iostream> #include <sys/statfs.h> #define RAMFS_MAGIC 0x858458F6LL int main() { int x = 0x858458F6; std::cout << x << std::endl; switch (x) //switch (static_cast<unsigned int>(x)) { case RAMFS_MAGIC: std::cout << "hi!" << std::endl; break; default: break; } struct statfs s; std::cout << sizeof(s.f_type) << std::endl; // Prints 8 on x86_64 return 0; }
_______________________________________________ Kde-frameworks-devel mailing list Kde-frameworks-devel@kde.org https://mail.kde.org/mailman/listinfo/kde-frameworks-devel