aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-02-16 01:57:07 +0000
committerTed Kremenek <kremenek@apple.com>2011-02-16 01:57:07 +0000
commita0125d8520f65aca581378c235384e7affefa1fc (patch)
treef414ba8e8fae306c6eae82dc32c20f45fbcd4879 /lib/Sema/SemaExpr.cpp
parenta1fdb0bc09aa0d17841cdbdd8c52cd1368251cbf (diff)
Add trivial buffer overflow checking in Sema.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125640 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index b0c337149d..760d5d58bc 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -294,6 +294,9 @@ void Sema::DefaultLvalueConversion(Expr *&E) {
if (T.hasQualifiers())
T = T.getUnqualifiedType();
+ if (const ArraySubscriptExpr *ae = dyn_cast<ArraySubscriptExpr>(E))
+ CheckArrayAccess(ae);
+
E = ImplicitCastExpr::Create(Context, T, CK_LValueToRValue,
E, 0, VK_RValue);
}
@@ -7242,6 +7245,11 @@ QualType Sema::CheckAssignmentOperands(Expr *LHS, Expr *&RHS,
Diag(UO->getOperatorLoc(), diag::note_indirection_through_null);
}
+ // Check for trivial buffer overflows.
+ if (const ArraySubscriptExpr *ae
+ = dyn_cast<ArraySubscriptExpr>(LHS->IgnoreParenCasts()))
+ CheckArrayAccess(ae);
+
// C99 6.5.16p3: The type of an assignment expression is the type of the
// left operand unless the left operand has qualified type, in which case
// it is the unqualified version of the type of the left operand.