#164 Few Issues (PVS-Studio)

None
closed-fixed
None
5
2013-10-07
2013-10-04
Andrey Karpov
No
V501 There are identical sub-expressions to the left and to the right of the '&&' operator: d1.xmin_ == 0.0 && d1.xmin_ == 0.0 distribution.cpp 281

Distribution ManipulateDistribution::convolve(
  const Distribution& d1, const Distribution& d2) {
  ....
  QL_REQUIRE (d1.xmin_ == 0.0 && d1.xmin_ == 0.0,
              "distributions offset larger than 0");
  ....
}
-------------------------------------------------------------------------------
V530 The return value of function 'empty' is required to be utilized. commoditycurve.cpp 70
V530 The return value of function 'empty' is required to be utilized. commoditycurve.cpp 71

void CommodityCurve::setPrices(std::map<Date, Real>& prices) {
  QL_REQUIRE(prices.size()>1, "too few prices");

  dates_.empty();
  data_.empty();

  for (std::map<Date, Real>::const_iterator i = prices.begin();
       i != prices.end(); i++)
  {
    dates_.push_back(i->first);
    data_.push_back(i->second);
  }
  ....
}
-------------------------------------------------------------------------------
V530 The return value of function 'empty' is required to be utilized. energycommodity.cpp 152

void EnergyCommodity::calculateSecondaryCostAmounts(
  const CommodityType& commodityType,
  Real totalQuantityValue,
  const Date& evaluationDate) const
{
  secondaryCostAmounts_.empty();
  ....
}
-------------------------------------------------------------------------------
V530 The return value of function 'remove' is required to be utilized. recursivecdoengine.hpp 172

template <class CDOEngine, class copulaT>
void RecursiveCdoEngine<CDOEngine, copulaT>::initialize() const {
  ....
  std::remove(lgds.begin(), lgds.end(), 0.);
  ....
}
-------------------------------------------------------------------------------
V519 The 'engine' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 98, 103. extendedtrees.cpp 103

boost::shared_ptr<VanillaOption> makeOption(....)
{
  switch (engineType) {
  case CRR:
    engine = boost::shared_ptr<PricingEngine>(
      new BinomialVanillaEngine<ExtendedCoxRossRubinstein>(..));
  case EQP:
    engine = boost::shared_ptr<PricingEngine>(
      new BinomialVanillaEngine<
        ExtendedAdditiveEQPBinomialTree>(..));
    break;
  ....
}

#add
V519 The 'engine' variable is assigned values twice successively. Perhaps this is a mistake. Check lines: 126, 130. europeanoption.cpp 130
-------------------------------------------------------------------------------
V557 Array overrun is possible. The value of 'i' index could reach 64. markovfunctional.cpp 176

Handle<YieldTermStructure> md0Yts() {
  ....
  double q6mh[] = {
    0.0001,0.0001,0.0001,0.0003,0.00055,0.0009,0.0014,0.0019,
    0.0025,0.0031,0.00325,0.00313,0.0031,0.00307,0.00309,
    0.00339,0.00316,0.00326,0.00335,0.00343,0.00358,0.00351,
    0.00388,0.00404,0.00425,0.00442,0.00462,0.00386,0.00491,
    0.00647,0.00837,0.01033,0.01218,0.01382,0.01527,0.01654,
    0.0177,0.01872,0.01959,0.0203,0.02088,0.02132,0.02164,
    0.02186,0.02202,0.02213,0.02222,0.02229,0.02234,0.02238,
    0.02241,0.02243,0.02244,0.02245,0.02247,0.0225,0.02284,
    0.02336,0.02407,0.0245 };
  ....
  for(int i=0;i<10+18+37;i++) {
    q6m.push_back(boost::shared_ptr<Quote>(new SimpleQuote(q6mh[i])));
  }
  ....
}
-------------------------------------------------------------------------------

PVS-Studio
Static Code Analyzer for C/C++/C++11
http://www.viva64.com/

Discussion

  • Luigi Ballabio
    Luigi Ballabio
    2013-10-07

    • status: open --> closed-fixed
    • assigned_to: Luigi Ballabio
    • Group: -->
     
  • Luigi Ballabio
    Luigi Ballabio
    2013-10-07

    Thanks for the report. Most of the issues had been fixed since last release, but a couple were still out there. I've fixed them now.