forked from OSchip/llvm-project
Fix a crash by division by zero in analyzer
Patch by takeshi-yoshimura! Differential Revision: http://reviews.llvm.org/D10145 llvm-svn: 240643
This commit is contained in:
parent
3bdcc8ce8f
commit
0dadfa8d05
|
@ -154,9 +154,13 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
|
|||
return &getValue( V1 * V2 );
|
||||
|
||||
case BO_Div:
|
||||
if (V2 == 0) // Avoid division by zero
|
||||
return nullptr;
|
||||
return &getValue( V1 / V2 );
|
||||
|
||||
case BO_Rem:
|
||||
if (V2 == 0) // Avoid division by zero
|
||||
return nullptr;
|
||||
return &getValue( V1 % V2 );
|
||||
|
||||
case BO_Add:
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// RUN: %clang_cc1 -analyze -analyzer-checker=unix.Malloc %s
|
||||
// Do not crash due to division by zero
|
||||
|
||||
int f(unsigned int a) {
|
||||
if (a <= 0) return 1 / a;
|
||||
return a;
|
||||
}
|
Loading…
Reference in New Issue