summaryrefslogtreecommitdiffstats
path: root/clang/lib/Checker/CastSizeChecker.cpp
diff options
context:
space:
mode:
authorJordy Rose <jediknil@belkadan.com>2010-06-20 04:30:57 +0000
committerJordy Rose <jediknil@belkadan.com>2010-06-20 04:30:57 +0000
commit2dd9b02cc85d40c21e2bf4f500751c318bf51ab3 (patch)
treea5e67779dbc5fa555c109befda25e335fe0fadb6 /clang/lib/Checker/CastSizeChecker.cpp
parent884a8fe5fa01f55aa53d9c2b02dbbf0f6c1a5837 (diff)
downloadbcm5719-llvm-2dd9b02cc85d40c21e2bf4f500751c318bf51ab3.tar.gz
bcm5719-llvm-2dd9b02cc85d40c21e2bf4f500751c318bf51ab3.zip
Casting to void* or any other pointer-to-sizeless type (e.g. function pointers) causes a divide-by-zero error. Simple fix: check if the pointee type size is 0 and bail out early if it is.
llvm-svn: 106401
Diffstat (limited to 'clang/lib/Checker/CastSizeChecker.cpp')
-rw-r--r--clang/lib/Checker/CastSizeChecker.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Checker/CastSizeChecker.cpp b/clang/lib/Checker/CastSizeChecker.cpp
index 754d775a65d..59ea9e0e84f 100644
--- a/clang/lib/Checker/CastSizeChecker.cpp
+++ b/clang/lib/Checker/CastSizeChecker.cpp
@@ -63,6 +63,11 @@ void CastSizeChecker::PreVisitCastExpr(CheckerContext &C, const CastExpr *CE) {
CharUnits RegionSize = CharUnits::fromQuantity(CI->getValue().getSExtValue());
CharUnits TypeSize = C.getASTContext().getTypeSizeInChars(ToPointeeTy);
+
+ // void, and a few other un-sizeable types
+ if (TypeSize.isZero())
+ return;
+
if (RegionSize % TypeSize != 0) {
if (ExplodedNode *N = C.GenerateSink()) {
if (!BT)
OpenPOWER on IntegriCloud