[all-commits] [llvm/llvm-project] 22357f: [analyzer] Avoid unnecessary super region invalida...
flovent via All-commits
all-commits at lists.llvm.org
Mon Jul 7 04:46:52 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 22357fe33a8a8cc221632e32cb443676f1feeda9
https://github.com/llvm/llvm-project/commit/22357fe33a8a8cc221632e32cb443676f1feeda9
Author: flovent <flbven at protonmail.com>
Date: 2025-07-07 (Mon, 07 Jul 2025)
Changed paths:
M clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
A clang/test/Analysis/cstring-should-not-invalidate.cpp
Log Message:
-----------
[analyzer] Avoid unnecessary super region invalidation in `CStringChecker` (#146212)
Bounded string functions takes smallest of two values as it's copy size
(`amountCopied` variable in `evalStrcpyCommon`), and it's used to
decided whether this operation will cause out-of-bound access and
invalidate it's super region if it does.
for `strlcat`: `amountCopied = min (size - dstLen - 1 , srcLen)`
for others: `amountCopied = min (srcLen, size)`
Currently when one of two values is unknown or `SValBuilder` can't
decide which one is smaller, `amountCopied` will remain `UnknownVal`,
which will invalidate copy destination's super region unconditionally.
This patch add check to see if one of these two values is definitely
in-bound, if so `amountCopied` has to be in-bound too, because it‘s less
than or equal to them, we can avoid the invalidation of super region and
some related false positives in this situation.
Note: This patch uses `size` as an approximation of `size - dstLen - 1`
in `strlcat` case because currently analyzer doesn't handle complex
expressions like this very well.
Closes #143807.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list