[clang] [clang][bytecode] Fix incorrect handling of arithmetic on string literals (PR #173212)
Oliver Hunt via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 23 15:42:24 PST 2025
================
@@ -294,12 +294,14 @@ bool Context::evaluateStrlen(State &Parent, const Expr *E, uint64_t &Result) {
if (!FieldDesc->isPrimitiveArray())
return false;
- if (Ptr.isDummy() || Ptr.isUnknownSizeArray())
+ if (Ptr.isDummy() || Ptr.isUnknownSizeArray() || Ptr.isPastEnd())
return false;
unsigned N = Ptr.getNumElems();
if (Ptr.elemSize() == 1) {
- Result = strnlen(reinterpret_cast<const char *>(Ptr.getRawAddress()), N);
+ unsigned Size = N - Ptr.getIndex();
+ Result =
+ strnlen(reinterpret_cast<const char *>(Ptr.getRawAddress()), Size);
return Result != N;
----------------
ojhunt wrote:
oh, the answer: I am a muppet and have two copies locally with nearly identical names. So that means that the tests are clearly not actually triggering the erroneous `Result != N` in this branch
https://github.com/llvm/llvm-project/pull/173212
More information about the cfe-commits
mailing list