Skip to content

Commit

Permalink
Fixes for issues discovered by Coverity
Browse files Browse the repository at this point in the history
  • Loading branch information
miatauro-NASA committed Nov 9, 2016
1 parent 21c437d commit 98547a2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
14 changes: 7 additions & 7 deletions src/PLASMA/NDDL/component/Interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2512,12 +2512,12 @@ void getVariableReferences(const Expr* expr, EvalContext& ctx,
}
//ExprVarDeclaration -> ?
else if(dynamic_cast<const ExprVarRef*>(expr) != NULL) {
dest.push_back(dynamic_cast<const ExprVarRef*>(expr)->eval(ctx).getValue());
dest.push_back(static_cast<const ExprVarRef*>(expr)->eval(ctx).getValue());
}
//ExprVarRef -> ?
//ExprAssignment -> ?
else if(dynamic_cast<const ExprConstraint*>(expr) != NULL) {
const ExprConstraint* e = dynamic_cast<const ExprConstraint*>(expr);
const ExprConstraint* e = static_cast<const ExprConstraint*>(expr);
std::vector<Expr*> args = e->getArgs();
for(std::vector<Expr*>::const_iterator it = args.begin();
it != args.end(); ++it) {
Expand All @@ -2531,7 +2531,7 @@ void getVariableReferences(const Expr* expr, EvalContext& ctx,
//ExprObjectTypeDefinition -> nothing
//ExprRuleTypeDefinition -> nothing
else if(dynamic_cast<const ExprMethodCall*>(expr) != NULL) {
const ExprMethodCall* e = dynamic_cast<const ExprMethodCall*>(expr);
const ExprMethodCall* e = static_cast<const ExprMethodCall*>(expr);
for(std::vector<Expr*>::const_iterator it = e->getArgs().begin();
it != e->getArgs().end(); ++it) {
checkError(*it != NULL, "Argument to method " << e->toString() << " is NULL.");
Expand All @@ -2546,7 +2546,7 @@ void getVariableReferences(const Expr* expr, EvalContext& ctx,
//ExprRelation -> ?
else if(dynamic_cast<const CExpr*>(expr) != NULL) {
if(dynamic_cast<const CExprFunction*>(expr) != NULL) {
const CExprFunction* e = dynamic_cast<const CExprFunction*>(expr);
const CExprFunction* e = static_cast<const CExprFunction*>(expr);
std::vector<CExpr*> args = e->getArgs();
for(std::vector<CExpr*>::const_iterator it = args.begin();
it != args.end(); ++it) {
Expand All @@ -2556,10 +2556,10 @@ void getVariableReferences(const Expr* expr, EvalContext& ctx,
}
else if(dynamic_cast<const CExprValue*>(expr) != NULL) {
//not sure this is right
dest.push_back(dynamic_cast<const CExprValue*>(expr)->eval(ctx).getValue());
dest.push_back(static_cast<const CExprValue*>(expr)->eval(ctx).getValue());
}
else if(dynamic_cast<const CExprBinary*>(expr) != NULL) {
const CExprBinary* e = dynamic_cast<const CExprBinary*>(expr);
const CExprBinary* e = static_cast<const CExprBinary*>(expr);
checkError(e->getLhs() != NULL, "LHS for " << e->toString() << " is NULL.");
checkError(e->getRhs() != NULL, "RHS for " << e->toString() << " is NULL.");
getVariableReferences(e->getLhs(), ctx, dest);
Expand All @@ -2574,7 +2574,7 @@ void getVariableReferences(const Expr* expr, EvalContext& ctx,
}
//RuleExpr -> ?
else if(dynamic_cast<const ExprIfGuard*>(expr) != NULL) {
const ExprIfGuard* e = dynamic_cast<const ExprIfGuard*>(expr);
const ExprIfGuard* e = static_cast<const ExprIfGuard*>(expr);
checkError(e->getLhs() != NULL, "LHS for " << e->toString() << " is NULL.");
checkError(e->getRhs() != NULL, "RHS for " << e->toString() << " is NULL.");
getVariableReferences(e->getLhs(), ctx, dest);
Expand Down
19 changes: 14 additions & 5 deletions src/PLASMA/PlanDatabase/base/Schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,12 @@ const std::set<std::string>& Schema::getAllObjectTypes() const {
membershipRelation.find(parentType);

// At this point we know if we do not have a hit, then try a parent
if(membershipRelation_it == membershipRelation.end() && hasParent(parentType))
return getMemberType(getParent(parentType), memberName);
if(membershipRelation_it == membershipRelation.end()) {
if(hasParent(parentType))
return getMemberType(getParent(parentType), memberName);
else
return "";
}

// Alternately, we have to have a hit
const NameValueVector& members = membershipRelation_it->second;
Expand All @@ -421,7 +425,7 @@ const std::set<std::string>& Schema::getAllObjectTypes() const {
return getMemberType(getParent(parentType), memberName);
}

unsigned int Schema::getIndexFromName(const std::string& parentType, const std::string& memberName) const {
int Schema::getIndexFromName(const std::string& parentType, const std::string& memberName) const {
check_error(hasMember(parentType, memberName),
memberName + " is not a member of " + parentType);

Expand All @@ -430,8 +434,13 @@ const std::set<std::string>& Schema::getAllObjectTypes() const {
membershipRelation.find(parentType);

// At this point we know if we do not have a hit, then try a parent
if(membershipRelation_it == membershipRelation.end() && hasParent(parentType))
return getIndexFromName(getParent(parentType), memberName);
if(membershipRelation_it == membershipRelation.end()) {
if(hasParent(parentType))
return getIndexFromName(getParent(parentType), memberName);
else
return -1;
}


// Alternately, we have to have a hit
const NameValueVector& members = membershipRelation_it->second;
Expand Down
2 changes: 1 addition & 1 deletion src/PLASMA/PlanDatabase/base/Schema.hh
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class LabelStr;
* @param type the type to search
* @param memberName the name of the member
*/
unsigned int getIndexFromName(const std::string& type, const std::string& memberName) const;
int getIndexFromName(const std::string& type, const std::string& memberName) const;

/**
* @brief Gets the name of a member from a types member list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,22 @@ std::string DbClientTransactionPlayer::getObjectAndType(const SchemaId schema,
bool rejectable,
bool isFact)
{
std::string sname(name ? name : "");
// The type may be qualified with an object name, in which case we should get the
// object and specify it. We will also have to generate the appropriate type designation
// by extracting the class from the object
ObjectId object;
std::string predicateType = getObjectAndType(getSchema(),m_client,type,object);

TokenId token = m_client->createToken(predicateType.c_str(),name,rejectable,isFact);
TokenId token = m_client->createToken(predicateType.c_str(),sname,rejectable,isFact);

if (!object.isNoId()) {
// We restrict the base domain permanently since the name is specifically mentioned on creation
token->getObject()->restrictBaseDomain(object->getThis()->baseDomain());
}

if (name != NULL) {
std::string std_name = name;
m_tokens[std_name] = token;
m_tokens[sname] = token;
}
else {
name = "NO_NAME_DBCTP";
Expand Down
2 changes: 2 additions & 0 deletions src/PLASMA/Resource/base/Resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ void Resource::init(const edouble initCapacityLb, const edouble initCapacityUb,
checkRuntimeError(prop.isValid(),
"Failed to get Resource propagator. Can't register profiles.");
ProfilePropagator* profileProp = dynamic_cast<ProfilePropagator*>(static_cast<Propagator*>(prop));
checkRuntimeError(profileProp != NULL,
"Failed to get Resource propagator. Can't register profiles.");
//TODO: have the capacity and limit profiles extend the Profile class and get added
//correctly
// profileProp->addProfile(m_capacityProfile);
Expand Down
5 changes: 4 additions & 1 deletion src/PLASMA/Solvers/component/OpenConditionDecisionPoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,10 @@ void SupportToken::execute()
if (slave->getFullTokenType() == m_token->getFullTokenType()) { // TODO: use ids
if (effectCnt == m_effectIndex) {
// TODO: eliminate the need for the dynamic cast below
TokenId slaveId = dynamic_cast<Token*>(slave)->getId();
Token* tok = dynamic_cast<Token*>(slave);
checkError(tok != NULL,
"Failed to cast " << slave->toString() << " to a token.");
TokenId slaveId = tok->getId();
m_targetEffect = slaveId;
m_dbClient->merge(m_targetEffect,m_token);
break;
Expand Down
24 changes: 10 additions & 14 deletions src/PLASMA/TemporalNetwork/base/TemporalNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,10 @@ Void TemporalNetwork::incDijkstraForward() {
check_error_variable(unsigned long BFbound = this->nodes.size());

while (true) {
Dnode* dnode = queue.popMinFromQueue();
if (dnode == NULL)
Timepoint* node = dynamic_cast<Timepoint*>(queue.popMinFromQueue());
if (node == NULL)
return;

Timepoint* node = dynamic_cast<Timepoint*>(dnode);

for (int i=0; i< node->outCount; i++) {
Dedge* edge = node->outArray[i];
Timepoint& next = dynamic_cast<Timepoint&>(edge->to);
Expand Down Expand Up @@ -801,11 +799,10 @@ Void TemporalNetwork::incDijkstraBackward() {
check_error_variable(unsigned long BFbound = this->nodes.size());

while (true) {
Dnode* dnode = queue.popMinFromQueue();
if(dnode == NULL)
return;

Timepoint* node = dynamic_cast<Timepoint*>(dnode);
Timepoint* node = dynamic_cast<Timepoint*>(queue.popMinFromQueue());
if(node == NULL)
return;

for (int i=0; i< node->inCount; i++) {
Dedge* edge = node->inArray[i];
Expand Down Expand Up @@ -839,10 +836,10 @@ Void TemporalNetwork::incDijkstraBackward() {
check_error_variable(unsigned long BFbound = this->nodes.size());

while (true) {
Dnode* dnode = queue.popMinFromQueue();
if (dnode == NULL)
Timepoint* node = dynamic_cast<Timepoint*>(queue.popMinFromQueue());
if (node == NULL)
return;
Timepoint* node = dynamic_cast<Timepoint*>(dnode);

for (int i=0; i< node->outCount; i++) {
Dedge* edge = node->outArray[i];
Timepoint& next = dynamic_cast<Timepoint&>(edge->to);
Expand Down Expand Up @@ -874,10 +871,9 @@ Void TemporalNetwork::incDijkstraBackward() {
check_error_variable(unsigned long BFbound = this->nodes.size());

while (true) {
Dnode* dnode = queue.popMinFromQueue();
if(dnode == NULL)
Timepoint* node = dynamic_cast<Timepoint*>(queue.popMinFromQueue());
if(node == NULL)
return;
Timepoint* node = dynamic_cast<Timepoint*>(dnode);
for (int i=0; i< node->inCount; i++) {
Dedge* edge = node->inArray[i];
Timepoint& next = dynamic_cast<Timepoint&>(edge->from);
Expand Down
2 changes: 1 addition & 1 deletion src/PLASMA/Utils/base/Entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EntityInternals {

std::map<eint, unsigned long int> m_entitiesByKey;
std::set<Entity*> m_discardedEntities;
bool m_purgeStatus, m_gcActive, m_gcRequired;
bool m_purgeStatus;
int m_key;
};

Expand Down

0 comments on commit 98547a2

Please sign in to comment.