Resolve Coverity issue with Parser::Transition's ownership of Action *.

This commit is somewhat subtle; it informs Coverity that
Parser::Transition only holds an Action* temporarily, and should never
create/delete one.  I believe runtime checkers should also understand
this OK.

Signed-off-by: John Hood <cgull@glup.org>
This commit is contained in:
John Hood
2015-06-10 19:38:00 -04:00
parent 6f4a59e20f
commit 8acee95c02
3 changed files with 14 additions and 4 deletions
+12 -3
View File
@@ -43,6 +43,8 @@ namespace Parser {
class Transition
{
public:
// Transition is only a courier for an Action; it should
// never create/delete one on its own.
Action *action;
State *next_state;
@@ -56,14 +58,21 @@ namespace Parser {
return *this;
}
virtual ~Transition() {}
virtual ~Transition()
{
// Indicate to checkers that we don't own *action anymore
action = NULL;
}
Transition( Action *s_action=new Ignore, State *s_next_state=NULL )
: action( s_action ), next_state( s_next_state )
{}
Transition( State *s_next_state )
: action( new Ignore ), next_state( s_next_state )
// This is only ever used in the 1-argument form;
// we use this instead of an initializer to
// tell Coverity the object never owns *action.
Transition( State *s_next_state, Action *s_action=new Ignore )
: action( s_action ), next_state( s_next_state )
{}
};
}