Skip to content

Commit

Permalink
Fix cppcheck reports (part2):
Browse files Browse the repository at this point in the history
- (error) Iterator 'oni' used after element has been erased
- (error) Dangerous iterator comparison using operator< on 'std::map'
- (style) Unused variable: it
- (error) Memory pointed to by 'counts' is freed twice
- (error) Memory pointed to by 'key' is freed twice
  • Loading branch information
serval2412 committed Dec 27, 2014
1 parent d5be107 commit c6c80dc
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 10 deletions.
2 changes: 0 additions & 2 deletions opencog/embodiment/Control/PerceptionActionInterface/PAI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3336,8 +3336,6 @@ Handle PAI::addOwnershipRelation(const Handle owner, const Handle owned, bool is
// This function is called by PsiActionSelectionAgent, when an action is timeout
void PAI::setPendingActionPlansFailed()
{
ActionPlanMap::iterator it;

// Note: use empty() rather than iterator directly, since setActionPlanStatus
// will erase action plans in pendingActionPlans if necessary.
while ( !pendingActionPlans.empty() ) {
Expand Down
3 changes: 1 addition & 2 deletions opencog/embodiment/Learning/PetaverseHC/hillclimber.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ struct hillclimber {
_current_program = oni->second;
_used_for_owner.insert(_current_program);

_ordered_best_estimates.erase(oni);

fitness_t cur_est_fit = oni->first;
_ordered_best_estimates.erase(oni);

if (cur_est_fit >= _best_fitness_estimated) {
_best_fitness_estimated = cur_est_fit;
Expand Down
1 change: 0 additions & 1 deletion opencog/guile/SchemeSmobTV.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static TruthValue *get_tv_from_kvp(SCM kvp, const char * subrname, int pos)
pos ++;
if (!scm_is_pair(kvp))
{
free(key);
scm_wrong_type_arg_msg(subrname, pos, kvp, "value following keyword");
}

Expand Down
4 changes: 2 additions & 2 deletions opencog/learning/statistics/Entropy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void Entropy::calculateEntropies(DataProvider<Metadata>* data)

for (int n = 1; n <= data->n_gram; ++n )
{
for( it = data->mDataMaps[n].begin(); it < data->mDataMaps[n].end(); ++it)
for( it = data->mDataMaps[n].begin(); it != data->mDataMaps[n].end(); ++it)
{
StatisticData& pieceData = (StatisticData)(it->second);
pieceData.entropy = (-1.0f) * pieceData.probability * log2(pieceData.probability);
Expand All @@ -54,7 +54,7 @@ void Entropy::calculateProbabilityAndEntropies(DataProvider<Metadata>* data)

for (int n = 1; n <= data->n_gram; ++n )
{
for( it = data->mDataMaps[n].begin(); it < data->mDataMaps[n].end(); ++it)
for( it = data->mDataMaps[n].begin(); it != data->mDataMaps[n].end(); ++it)
{
StatisticData& pieceData = (StatisticData)(it->second);
pieceData.probability = ((float)(pieceData.count))/((float)(data->mRawDataNumbers[n]));
Expand Down
2 changes: 1 addition & 1 deletion opencog/learning/statistics/InteractionInformation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void InteractionInformation::calculateInteractionInformations(DataProvider<Metad

for (int n = 1; n <= data->n_gram; ++n )
{
for( it = data->mDataMaps[n].begin(); it < data->mDataMaps[n].end(); ++it)
for( it = data->mDataMaps[n].begin(); it != data->mDataMaps[n].end(); ++it)
{
StatisticData& pieceData = (StatisticData)(it->second);
pieceData.interactionInformation = calculateInteractionInformation((string)(it->first), data);
Expand Down
2 changes: 1 addition & 1 deletion opencog/learning/statistics/Probability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Probability::calculateProbabilities(DataProvider<Metadata>* data)

for (int n = 1; n <= data->n_gram; ++n )
{
for( it = data->mDataMaps[n].begin(); it < data->mDataMaps[n].end(); ++it)
for( it = data->mDataMaps[n].begin(); it != data->mDataMaps[n].end(); ++it)
{
StatisticData& pieceData = (StatisticData)(it->second);
pieceData.probability = ((float)(pieceData.count))/((float)(data->mRawDataNumbers[n]));
Expand Down
3 changes: 2 additions & 1 deletion opencog/util/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -2493,9 +2493,10 @@ void kcluster (int nclusters, int nrows, int ncolumns,
if (transpose==0) ok = makedatamask(nclusters, ndata, &cdata, &cmask);
else ok = makedatamask(ndata, nclusters, &cdata, &cmask);
if(!ok)
{ free(counts);
{
if(npass>1)
{ free(tclusterid);
free(counts);
free(mapping);
return;
}
Expand Down

0 comments on commit c6c80dc

Please sign in to comment.