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:
@@ -63,6 +63,7 @@ std::list<Parser::Action *> Parser::Parser::input( wchar_t ch )
|
|||||||
}
|
}
|
||||||
|
|
||||||
append_or_delete( tx.action, ret );
|
append_or_delete( tx.action, ret );
|
||||||
|
tx.action = NULL;
|
||||||
|
|
||||||
if ( tx.next_state != NULL ) {
|
if ( tx.next_state != NULL ) {
|
||||||
append_or_delete( tx.next_state->enter(), ret );
|
append_or_delete( tx.next_state->enter(), ret );
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ Transition State::anywhere_rule( wchar_t ch ) const
|
|||||||
return Transition( &family->s_CSI_Entry );
|
return Transition( &family->s_CSI_Entry );
|
||||||
}
|
}
|
||||||
|
|
||||||
return Transition( NULL, NULL ); /* don't allocate an Ignore action */
|
return Transition(( State * )NULL, NULL ); /* don't allocate an Ignore action */
|
||||||
}
|
}
|
||||||
|
|
||||||
Transition State::input( wchar_t ch ) const
|
Transition State::input( wchar_t ch ) const
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ namespace Parser {
|
|||||||
class Transition
|
class Transition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// Transition is only a courier for an Action; it should
|
||||||
|
// never create/delete one on its own.
|
||||||
Action *action;
|
Action *action;
|
||||||
State *next_state;
|
State *next_state;
|
||||||
|
|
||||||
@@ -56,14 +58,21 @@ namespace Parser {
|
|||||||
|
|
||||||
return *this;
|
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 )
|
Transition( Action *s_action=new Ignore, State *s_next_state=NULL )
|
||||||
: action( s_action ), next_state( s_next_state )
|
: action( s_action ), next_state( s_next_state )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Transition( State *s_next_state )
|
// This is only ever used in the 1-argument form;
|
||||||
: action( new Ignore ), next_state( s_next_state )
|
// 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 )
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user