@@ -17,39 +17,42 @@ class MyDZChecker
1717 CheckerContext &C) const ;
1818
1919public:
20- void checkPreStmt (BinaryOperator const *B, CheckerContext &C) const ;
2120MyDZChecker ()
22- : BT(std::make_unique<BugType>(this , " hello-my-div-by-zero" ,
23- categories::LogicError)){}
21+ : BT(std::make_unique<BugType>(this , " chx-DBZ" , categories::LogicError)){
22+ }
23+ void checkPreStmt (BinaryOperator const *B, CheckerContext &C) const ;
2424void checkPostCall (CallEvent const &, CheckerContext &) const ;
2525};
2626
2727void MyDZChecker::reportBug (const char *Msg, ProgramStateRef StateZero,
2828 CheckerContext &C) const {
2929if (ExplodedNode *N = C.generateSink (StateZero)){
3030 BugReport *R = new BugReport (*BT, Msg, N);
31- bugreporter::trackNullOrUndefValue (N, bugreporter::GetDenomExpr (N), *R);
31+ // bugreporter::trackNullOrUndefValue(N, bugreporter::GetDenomExpr(N), *R);
3232 C.emitReport (R);
3333 }
3434}
3535
3636void MyDZChecker::checkPreStmt (const BinaryOperator *B,
3737 CheckerContext &C) const {
3838 BinaryOperator::Opcode Op = B->getOpcode ();
39- if (Op != BO_Div && Op != BO_Rem && Op != BO_DivAssign && Op != BO_RemAssign)
39+ if (Op != BinaryOperatorKind::BO_Div && Op != BinaryOperatorKind::BO_Rem &&
40+ Op != BinaryOperatorKind::BO_DivAssign &&
41+ Op != BinaryOperatorKind::BO_RemAssign)
4042return ;
4143
4244if (!B->getRHS ()->getType ()->isScalarType ()) return ;
4345
4446 SVal Denom = C.getState ()->getSVal (B->getRHS (), C.getLocationContext ());
45- Optional<DefinedSVal> DV = Denom.getAs <DefinedSVal>();
47+ SVal Numer = C.getState ()->getSVal (B->getLHS (), C.getLocationContext ());
48+ Optional<DefinedSVal> DVR = Denom.getAs <DefinedSVal>();
49+ Optional<DefinedSVal> DVL = Numer.getAs <DefinedSVal>();
4650
47- if (!DV ) return ;
51+ if (!DVR ) return ;
4852
49- // Check for divide by zero.
5053 ConstraintManager &CM = C.getConstraintManager ();
5154 ProgramStateRef stateNotZero, stateZero;
52- std::tie (stateNotZero, stateZero) = CM.assumeDual (C.getState (), *DV );
55+ std::tie (stateNotZero, stateZero) = CM.assumeDual (C.getState (), *DVR );
5356
5457if (stateNotZero != nullptr ){
5558 stateNotZero->dump ();
@@ -58,19 +61,19 @@ void MyDZChecker::checkPreStmt(const BinaryOperator *B,
5861 stateZero->dump ();
5962 }
6063
61- if (!stateNotZero){
64+ // surely 0
65+ if (stateNotZero == nullptr ){
6266assert (stateZero);
63- reportBug (" my-divide-by-zero " , stateZero, C);
67+ reportBug (" chx.DBZ - DBZ " , stateZero, C);
6468return ;
6569 }
6670
6771// / std::cerr << (stateNotZero != nullptr) << " " << (stateZero != nullptr)
6872// / << '\n'
6973
70- bool TaintedD = C.getState ()->isTainted (*DV);
71- // / if (TaintedD){
74+ bool TaintedD = C.getState ()->isTainted (*DVR);
7275if ((stateNotZero != nullptr && stateZero != nullptr && TaintedD)){
73- reportBug (" tainted, possibly div zero " , stateZero, C);
76+ reportBug (" chx.DBZ - tainted DBZ " , stateZero, C);
7477return ;
7578 }
7679
0 commit comments