3 ms·
If you're going to read byte-level data you should be using a char pointer. The author also speculates on how common this "bug" is. I'd say 15000 Debian packag
by phkahler 3y ago
If you're going to read byte-level data you should be using a char pointer.
The author also speculates on how common this "bug" is. I'd say 15000 Debian packages that work properly indicates that just about nobody is relying on this undefined behavior.
- unnah 3y agoGetting to that point has required years of maintenance work since compiler writers started interpreting more and more undefined behaviour as optimization opportunities. At least now we have UBSAN to actually test for undefined behaviour at runtime.
- assbuttbuttass 3y agoUndefined behavior doesn't necessarily mean the program will exhibit an issue. It could silently break with a future version of the compiler, which it sounds like was the case here
- dzaima 3y agoFor one, the linux kernel itself relies on this UB - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93031#c5 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93031#c5, linked from OP. And indeed linux would hit UBSAN reports on those, but just disables it if native unaligned load/store is configured - last paragraph of https://github.com/torvalds/linux/blob/706a741595047797872e669b3101429ab8d378ef/Documentation/dev-tools/ubsan.rst#L79 https://github.com/torvalds/linux/blob/706a741595047797872e6... At present there's almost no reliance on this UB by compilers on something that actually has a chance of affecting real code, so it's not particularly unexpected that software appears to work.
- deleted 3y ago[deleted]