5th byte of a varint can't be bigger than 0x0f, fix a test and add an
assertion.
Details
- Reviewers
sammccall - Commits
- rG6e7dd1e3e117: [clangd] Assert on varint encoding
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clangd/index/Serialization.cpp | ||
---|---|---|
90 | I'm fine with an assert, but this still leaves us with the suspected UB in NDEBUG mode, which doesn't seem OK. The issue here is integral promotion rules say that uint_8 << anything uses *signed* arithmetic. And same for a bunch of the other operations. I think the clearest thing to do is explicitly type B as uint32_t, so no expression it is in can ever be promoted to (signed) int. | |
clang-tools-extra/clangd/unittests/SerializationTests.cpp | ||
371 | /shamecube In my defense, I grew up on a 68k mac... little endian is weird |
clang-tools-extra/clangd/index/Serialization.cpp | ||
---|---|---|
90 | hmm, actually it's also invalid to have the More bit set on the last byte... |
I'm fine with an assert, but this still leaves us with the suspected UB in NDEBUG mode, which doesn't seem OK.
(As noted on D91258 I'm not sure this is actual UB under C++ rules)
The issue here is integral promotion rules say that uint_8 << anything uses *signed* arithmetic. And same for a bunch of the other operations.
I think the clearest thing to do is explicitly type B as uint32_t, so no expression it is in can ever be promoted to (signed) int.
(Unless int is bigger than 32 bits, in which case we've always got enough bits to shift into)