[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 18:07:19 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:
Ok, worked out an additional test case that fails with the `Result != N` check instead of `Result != Size`.
Also discovered that we don't warn when the source string is not null terminated
https://github.com/llvm/llvm-project/pull/173212
More information about the cfe-commits
mailing list