Skip to content

Commit

Permalink
libstage: fix errors/warnings reported by cppcheck v1.72 (also fixes …
Browse files Browse the repository at this point in the history
…issue rtv#46)
  • Loading branch information
CodeFinder2 committed Feb 7, 2017
1 parent 63e7610 commit 0ffdd6a
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 150 deletions.
4 changes: 2 additions & 2 deletions libstage/blockgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void BlockGroup::LoadBlock( Worldfile* wf, int entity )

void BlockGroup::LoadBitmap( const std::string& bitmapfile, Worldfile* wf )
{
PRINT_DEBUG1( "attempting to load bitmap \"%s\n", bitmapfile );
PRINT_DEBUG1( "attempting to load bitmap \"%s\n", bitmapfile.c_str() );

std::string full;

Expand All @@ -311,7 +311,7 @@ void BlockGroup::LoadBitmap( const std::string& bitmapfile, Worldfile* wf )
fputs( buf, stdout );
fflush( stdout );

PRINT_DEBUG1( "attempting to load image %s", full );
PRINT_DEBUG1( "attempting to load image %s", full.c_str() );

Color col( 1.0, 0.0, 1.0, 1.0 );

Expand Down
4 changes: 2 additions & 2 deletions libstage/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,10 @@ void Canvas::renderFrame()
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

if( showOccupancy )
((WorldGui*)world)->DrawOccupancy();
world->DrawOccupancy();

if( showVoxels )
((WorldGui*)world)->DrawVoxels();
world->DrawVoxels();


if( ! world->rt_cells.empty() )
Expand Down
2 changes: 1 addition & 1 deletion libstage/file_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace Stg

ranOnce = true;

PRINT_DEBUG1("FileManager - INIT: %d paths in search paths\n", paths.size() );
PRINT_DEBUG1("FileManager - INIT: %d paths in search paths\n", int(paths.size()) );
}

// search the path list
Expand Down
2 changes: 1 addition & 1 deletion libstage/glutgraphics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void ExampleDriver_Register(DriverTable* table)
// pre-Setup() setup.
ExampleDriver::ExampleDriver(ConfigFile* cf, int section)
: Driver(cf, section, false, PLAYER_MSGQUEUE_DEFAULT_MAXLEN,
PLAYER_GRAPHICS3D_CODE)
PLAYER_GRAPHICS3D_CODE), foop(0)
{
// Read an option from the configuration file
//this->foop = cf->ReadInt(section, "foo", 0);
Expand Down
8 changes: 5 additions & 3 deletions libstage/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ bool Model::IsRelated( const Model* that ) const
return true;

// wind up to top-level object
Model* candidate = (Model*)this;
const Model* candidate = this;
while( candidate->parent )
{
// shortcut out if we found it on the way up the tree
Expand Down Expand Up @@ -968,7 +968,9 @@ Model::RasterVis::RasterVis()
height(0),
cellwidth(0),
cellheight(0),
pts()
pts(),
subs(0),
used(0)
{

}
Expand Down Expand Up @@ -1635,7 +1637,7 @@ void Model::LoadControllerModule( const char* lib )

// the library name is the first word in the string
char libname[256];
sscanf( lib, "%s %*s", libname );
sscanf( lib, "%255s %*s", libname );

if(( handle = lt_dlopenext( libname ) ))
{
Expand Down
9 changes: 5 additions & 4 deletions libstage/model_actuator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ ModelActuator::ModelActuator( World* world,
min_position(0),
max_position(1),
start_position(0),
cosa(0.0),
sina(0.0),
control_mode( CONTROL_VELOCITY ),
actuator_type( TYPE_LINEAR ),
axis(0,0,0)
Expand Down Expand Up @@ -183,10 +185,7 @@ void ModelActuator::Load( void )

void ModelActuator::Update( void )
{
PRINT_DEBUG1( "[%lu] actuator update", 0 );

// stop by default
double velocity = 0;
PRINT_DEBUG1( "[%d] actuator update", 0 );

// update current position
Pose CurrentPose = GetPose();
Expand Down Expand Up @@ -215,6 +214,8 @@ void ModelActuator::Update( void )

if( this->subs ) // no driving if noone is subscribed
{
// stop by default
double velocity = 0;
switch( control_mode )
{
case CONTROL_VELOCITY :
Expand Down
4 changes: 2 additions & 2 deletions libstage/model_blinkenlight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ ModelBlinkenlight::ModelBlinkenlight( World* world,
period( 1000 ),
on( true )
{
PRINT_DEBUG2( "Constructing ModelBlinkenlight %d (%s)\n",
id, typestr );
PRINT_DEBUG2( "Constructing ModelBlinkenlight %u (%s)\n",
id, type.c_str() );

// Set up sensible defaults

Expand Down
10 changes: 5 additions & 5 deletions libstage/model_blobfinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ModelBlobfinder::ModelBlobfinder( World* world,
Model* parent,
const std::string& type ) :
Model( world, parent, type ),
vis( world ),
blob_vis( world ),
blobs(),
colors(),
fov( DEFAULT_BLOBFINDERFOV ),
Expand All @@ -93,11 +93,11 @@ ModelBlobfinder::ModelBlobfinder( World* world,
scan_height( DEFAULT_BLOBFINDERSCANHEIGHT ),
scan_width( DEFAULT_BLOBFINDERSCANWIDTH )
{
PRINT_DEBUG2( "Constructing ModelBlobfinder %d (%s)\n",
id, typestr );
PRINT_DEBUG2( "Constructing ModelBlobfinder %u (%s)\n",
id, type.c_str() );
ClearBlocks();

AddVisualizer( &this->vis, true );
AddVisualizer( &this->blob_vis, true );
}


Expand All @@ -106,7 +106,7 @@ ModelBlobfinder::~ModelBlobfinder( void )
}

static bool blob_match( Model* candidate,
Model* finder,
const Model* finder,
const void* dummy )
{
(void)dummy; // avoid warning about unused var
Expand Down
8 changes: 4 additions & 4 deletions libstage/model_bumper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ModelBumper::ModelBumper( World* world,
: Model( world, parent, type ),
bumpervis()
{
PRINT_DEBUG2( "Constructing ModelBumper %d (%s)\n",
PRINT_DEBUG2( "Constructing ModelBumper %u (%s)\n",
id, type.c_str() );

// Set up sensible defaults
Expand Down Expand Up @@ -144,14 +144,14 @@ void ModelBumper::Load( void )
// allow individual configuration of transducers
for( unsigned int i = 0; i < bumper_count; i++)
{
snprintf(key, sizeof(key), "bpose[%d]", i);
snprintf(key, sizeof(key), "bpose[%u]", i);
wf->ReadTuple( wf_entity, key, 0, 4, "llla",
&bumpers[i].pose.x,
&bumpers[i].pose.y,
&bumpers[i].pose.z,
&bumpers[i].pose.a );

snprintf(key, sizeof(key), "blength[%d]", i);
snprintf(key, sizeof(key), "blength[%u]", i);
bumpers[i].length = wf->ReadLength( wf_entity, key, bumpers[i].length );
}

Expand All @@ -160,7 +160,7 @@ void ModelBumper::Load( void )
}

static bool bumper_match( Model* candidate,
Model* finder, const void* dummy )
const Model* finder, const void* dummy )
{
// Ignore myself, my children, and my ancestors.
return( //candidate->vis.obstacle_return &&
Expand Down
16 changes: 4 additions & 12 deletions libstage/model_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ ModelCamera::ModelCamera( World* world,
_yaw_offset( 0.0 ),
_pitch_offset( 0.0 )
{
PRINT_DEBUG2( "Constructing ModelCamera %d (%s)\n",
id, typestr );
PRINT_DEBUG2( "Constructing ModelCamera %u (%s)\n",
id, type.c_str() );

WorldGui* world_gui = dynamic_cast< WorldGui* >( world );

Expand All @@ -125,13 +125,13 @@ ModelCamera::ModelCamera( World* world,

ModelCamera::~ModelCamera()
{
if( _frame_data != NULL ) {
//dont forget about GetFrame() //TODO merge these together
if( _frame_data != NULL ) {
delete[] _frame_data;
delete[] _frame_color_data;
delete[] _vertexbuf_cache;
delete[] _camera_quads;
delete[] _camera_colors;
_frame_data = NULL;
}
}

Expand Down Expand Up @@ -168,14 +168,6 @@ bool ModelCamera::GetFrame( void )
return false;

if( _frame_data == NULL ) {
if( _frame_data != NULL ) {
//don't forget about destructor
delete[] _frame_data;
delete[] _frame_color_data;
delete[] _vertexbuf_cache;
delete[] _camera_quads;
delete[] _camera_colors;
}
_frame_data = new GLfloat[ _width * _height ]; //assumes a max of depth 4
_frame_color_data = new GLubyte[ 4 * _width * _height ]; //for RGBA

Expand Down
2 changes: 1 addition & 1 deletion libstage/model_draw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ void Model::DrawFlagList( void )

for( std::list<Flag*>::reverse_iterator it( flag_list.rbegin());
it != flag_list.rend();
it++ )
++it )
{
double sz = (*it)->GetSize();
double d = sz/2.0;
Expand Down
2 changes: 1 addition & 1 deletion libstage/model_fiducial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ ModelFiducial::~ModelFiducial( void )
}

static bool fiducial_raytrace_match( Model* candidate,
Model* finder,
const Model* finder,
const void* dummy )
{
(void)dummy; // avoid warning about unused var
Expand Down
2 changes: 1 addition & 1 deletion libstage/model_gripper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void ModelGripper::Update()


static bool gripper_raytrace_match( Model* hit,
Model* finder,
const Model* finder,
const void* dummy )
{
(void)dummy; // avoid warning about unused var
Expand Down
16 changes: 8 additions & 8 deletions libstage/model_position.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ ModelPosition::ModelPosition( World* world,
wpvis(),
posevis()
{
PRINT_DEBUG2( "Constructing ModelPosition %d (%s)\n",
id, typestr );
PRINT_DEBUG2( "Constructing ModelPosition %u (%s)\n",
id, type.c_str() );

// assert that Update() is reentrant for this derived model
thread_safe = false;
Expand Down Expand Up @@ -406,17 +406,17 @@ void ModelPosition::Update( void )
{
PRINT_DEBUG( "position control mode" );

double x_error = goal.x - est_pose.x;
double y_error = goal.y - est_pose.y;
double a_error = normalize( goal.a - est_pose.a );
const double x_error = goal.x - est_pose.x;
const double y_error = goal.y - est_pose.y;
double a_error = normalize( goal.a - est_pose.a );

PRINT_DEBUG3( "errors: %.2f %.2f %.2f\n", x_error, y_error, a_error );

// speed limits for controllers
// TODO - have these configurable
double max_speed_x = 0.4;
double max_speed_y = 0.4;
double max_speed_a = 1.0;
const double max_speed_x = 0.4;
const double max_speed_y = 0.4;
const double max_speed_a = 1.0;

switch( drive_mode )
{
Expand Down
11 changes: 5 additions & 6 deletions libstage/model_ranger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ ModelRanger::ModelRanger( World* world,
Model* parent,
const std::string& type )
: Model( world, parent, type ),
vis( world )
ranger_vis( world )
{
PRINT_DEBUG2( "Constructing ModelRanger %d (%s)\n",
id, type );
PRINT_DEBUG2( "Constructing ModelRanger %u (%s)\n", id, type.c_str() );

// Set up sensible defaults

Expand All @@ -109,7 +108,7 @@ ModelRanger::ModelRanger( World* world,

this->SetGeom( Geom( Pose(), RANGER_SIZE ));

AddVisualizer( &vis, true );
AddVisualizer( &ranger_vis, true );
}

ModelRanger::~ModelRanger()
Expand Down Expand Up @@ -155,7 +154,7 @@ void ModelRanger::Sensor::Load( Worldfile* wf, int entity )


static bool ranger_match( Model* hit,
Model* finder,
const Model* finder,
const void* dummy )
{
(void)dummy; // avoid warning about unused var
Expand Down Expand Up @@ -271,7 +270,7 @@ void ModelRanger::Sensor::Visualize( ModelRanger::Vis* vis, ModelRanger* rgr ) c

// pack the ranger hit points into a vertex array for fast rendering
GLfloat pts[2*(sample_count+1)];
glVertexPointer( 2, GL_FLOAT, 0, &pts[0] );
glVertexPointer( 2, GL_FLOAT, 0, pts );

pts[0] = 0.0;
pts[1] = 0.0;
Expand Down
2 changes: 2 additions & 0 deletions libstage/option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Option::Option( const std::string& n,
wf_token( tok ),
shortcut( key ),
menu( NULL ),
menuIndex( 0 ),
menuCb( NULL ),
menuCbWidget( NULL ),
_world( world ),
htname( n )
{
Expand Down
5 changes: 2 additions & 3 deletions libstage/options_dlg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ namespace Stg {
void OptionsDlg::updateChecks() {
if (scroll->children())
scroll->clear();
scroll->begin();
Fl_Check_Button* check;
scroll->begin();
for ( unsigned int i=0; i<options.size(); i++ ) {
check = new Fl_Check_Button( 0,boxH*(i+1)+vm, scroll->w(), boxH, options[ i ]->name().c_str() );
Fl_Check_Button* check = new Fl_Check_Button( 0,boxH*(i+1)+vm, scroll->w(), boxH, options[ i ]->name().c_str() );
if ( options[ i ]->val() )
check->set();
check->callback( checkChanged, this );
Expand Down
12 changes: 4 additions & 8 deletions libstage/region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ Stg::Region::~Region()

void Stg::Region::AddBlock()
{
++count;
assert(count>0);
++count;
superregion->AddBlock();
}

void Stg::Region::RemoveBlock()
{
--count;
assert(count>=0);
--count;
superregion->RemoveBlock();

// if there's nothing in this region, we can garbage collect the
Expand All @@ -55,14 +53,12 @@ SuperRegion::~SuperRegion()

void SuperRegion::AddBlock()
{
++count;
assert(count>0);
++count;
}

void SuperRegion::RemoveBlock()
{
--count;
assert(count>=0);
--count;
}


Expand Down
Loading

0 comments on commit 0ffdd6a

Please sign in to comment.