Skip to content

Commit

Permalink
PR IntelRealSense#12754 from Eran: fix coverity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel authored Mar 17, 2024
2 parents 18489a6 + e12e35e commit 70d4418
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ HANDLE_EXCEPTIONS_AND_RETURN(nullptr, options, option, value)
static void populate_options_list( rs2_options_list * updated_options_list,
options_watcher::options_and_values const & updated_options )
{
for( auto id_value : updated_options )
for( auto & id_value : updated_options )
{
options_watcher::option_and_value const & option_and_value = id_value.second;
updated_options_list->list.push_back(
Expand Down
5 changes: 3 additions & 2 deletions third-party/realdds/src/dds-metadata-syncer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const size_t dds_metadata_syncer::max_md_queue_size = 8;
const size_t dds_metadata_syncer::max_frame_queue_size = 2;


dds_metadata_syncer::dds_metadata_syncer() :
_is_alive( std::make_shared< bool >( true ) )
dds_metadata_syncer::dds_metadata_syncer()
: _is_alive( std::make_shared< bool >( true ) )
, _on_frame_release( nullptr )
{
}

Expand Down
43 changes: 24 additions & 19 deletions third-party/realdds/src/dds-option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,38 @@ bool type_from_value( std::string & type, json const & j, json const & j2, Rest.

static std::string parse_type( json const & j, size_t size, dds_option::option_properties & props )
{
for( auto p : props )
for( auto it = props.begin(); it != props.end(); ++it )
{
switch( p.length() )
switch( it->length() )
{
case 5:
if( p == "float" )
return props.erase( p ), p;
break;
if( 0 == it->compare( "float" ) )
break;
continue;
case 6:
if( p == "string" )
return props.erase( p ), p;
break;
if( 0 == it->compare( "string" ) )
break;
continue;
case 3:
if( p == "int" )
return props.erase( p ), p;
break;
if( 0 == it->compare( "int" ) )
break;
continue;
case 7:
if( p == "boolean" )
return props.erase( p ), p;
break;
if( 0 == it->compare( "boolean" ) )
break;
continue;
case 4:
if( p == "IPv4" )
return props.erase( p ), p;
if( 5 == size && p == "enum" )
return props.erase( p ), p;
break;
if( 0 == it->compare( "IPv4" ) )
break;
if( 5 == size && 0 == it->compare( "enum" ) )
break;
continue;
default:
continue;
}
std::string property = *it;
props.erase( it );
return property;
}
// If not from the properties, try from the value at index 1:
std::string type;
Expand Down
14 changes: 7 additions & 7 deletions third-party/realdds/src/dds-participant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ std::string dds_participant::print( dds_guid const & guid_to_print ) const

void dds_participant::on_writer_added( dds_guid guid, char const * topic_name )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand All @@ -332,7 +332,7 @@ void dds_participant::on_writer_added( dds_guid guid, char const * topic_name )

void dds_participant::on_writer_removed( dds_guid guid, char const * topic_name )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand All @@ -345,7 +345,7 @@ void dds_participant::on_writer_removed( dds_guid guid, char const * topic_name

void dds_participant::on_reader_added( dds_guid guid, char const * topic_name )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand All @@ -358,7 +358,7 @@ void dds_participant::on_reader_added( dds_guid guid, char const * topic_name )

void dds_participant::on_reader_removed( dds_guid guid, char const * topic_name )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand All @@ -371,7 +371,7 @@ void dds_participant::on_reader_removed( dds_guid guid, char const * topic_name

void dds_participant::on_participant_added( dds_guid guid, char const * participant_name )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand All @@ -384,7 +384,7 @@ void dds_participant::on_participant_added( dds_guid guid, char const * particip

void dds_participant::on_participant_removed( dds_guid guid, char const * participant_name )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand All @@ -397,7 +397,7 @@ void dds_participant::on_participant_removed( dds_guid guid, char const * partic

void dds_participant::on_type_discovery( char const * topic_name, eprosima::fastrtps::types::DynamicType_ptr dyn_type )
{
for( auto wl : _listeners )
for( auto & wl : _listeners )
{
if( auto l = wl.lock() )
{
Expand Down
2 changes: 1 addition & 1 deletion third-party/realdds/src/dds-stream-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void dds_stream_base::set_recommended_filters( std::vector< std::string > && rec
if( !_recommended_filters.empty() )
DDS_THROW( runtime_error, "stream '" + _name + "' recommended filters are already set" );

_recommended_filters = recommended_filters;
_recommended_filters = std::move( recommended_filters );
}


Expand Down
10 changes: 5 additions & 5 deletions tools/dds/dds-adapter/lrs-device-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ std::vector< std::shared_ptr< realdds::dds_stream_server > > lrs_device_controll
std::map< std::string, std::set< realdds::video_intrinsics > > stream_name_to_video_intrinsics;

// Iterate over all profiles of all sensors and build appropriate dds_stream_servers
for( auto sensor : _rs_dev.query_sensors() )
for( auto & sensor : _rs_dev.query_sensors() )
{
std::string const sensor_name = sensor.get_info( RS2_CAMERA_INFO_NAME );
// We keep a copy of the sensors throughout the run time:
Expand Down Expand Up @@ -249,9 +249,7 @@ std::vector< std::shared_ptr< realdds::dds_stream_server > > lrs_device_controll
server->init_profiles( profiles, default_profile_index );

// Get supported options and recommended filters for this stream
realdds::dds_options stream_options;
std::vector< std::string > filter_names;
for( auto sensor : _rs_dev.query_sensors() )
for( auto & sensor : _rs_dev.query_sensors() )
{
std::string const sensor_name = sensor.get_info( RS2_CAMERA_INFO_NAME );
if( server->sensor_name().compare( sensor_name ) != 0 )
Expand All @@ -261,6 +259,7 @@ std::vector< std::shared_ptr< realdds::dds_stream_server > > lrs_device_controll
// only need to do this once per sensor!
if( sensors_handled.emplace( sensor_name ).second )
{
realdds::dds_options stream_options;
auto supported_options = sensor.get_supported_options();
for( auto option_id : supported_options )
{
Expand Down Expand Up @@ -310,6 +309,7 @@ std::vector< std::shared_ptr< realdds::dds_stream_server > > lrs_device_controll
}

auto recommended_filters = sensor.get_recommended_filters();
std::vector< std::string > filter_names;
for( auto const & filter : recommended_filters )
filter_names.push_back( filter.get_info( RS2_CAMERA_INFO_NAME ) );

Expand All @@ -332,7 +332,7 @@ extrinsics_map get_extrinsics_map( const rs2::device & dev )
std::map< std::string, rs2::stream_profile > stream_name_to_rs2_stream_profile;

// Iterate over profiles of all sensors and split to streams
for( auto sensor : dev.query_sensors() )
for( auto & sensor : dev.query_sensors() )
{
auto stream_profiles = sensor.get_stream_profiles();
std::for_each( stream_profiles.begin(),
Expand Down
2 changes: 1 addition & 1 deletion tools/dds/dds-adapter/lrs-device-watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void lrs_device_watcher::run( std::function< void( rs2::device ) > add_device_cb
}
}

for( auto device_to_remove : devices_to_remove )
for( auto & device_to_remove : devices_to_remove )
{
try
{
Expand Down
14 changes: 7 additions & 7 deletions tools/dds/dds-sniffer/rs-dds-sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ uint32_t dds_sniffer::calc_max_indentation() const
uint32_t indentation = 0;
uint32_t max_indentation = 0;

for( auto topic : _topics_info_by_name ) //_dds_entities_lock locked by print_topics()
for( auto & topic : _topics_info_by_name ) //_dds_entities_lock locked by print_topics()
{
if( filter_topic( topic.first, _root ) )
continue;
Expand Down Expand Up @@ -548,17 +548,17 @@ void dds_sniffer::print_topics_machine_readable() const
{
std::lock_guard< std::mutex > lock( _dds_entities_lock );

for( auto topic : _topics_info_by_name )
for( auto & topic : _topics_info_by_name )
{
if( filter_topic( topic.first, _root ) )
continue;

for( auto writer : topic.second.writers )
for( auto & writer : topic.second.writers )
{
std::cout << topic.first << ",";
print_topic_writer( writer );
}
for( auto reader : topic.second.readers )
for( auto & reader : topic.second.readers )
{
std::cout << topic.first << ",";
print_topic_reader( reader );
Expand All @@ -575,7 +575,7 @@ void dds_sniffer::print_topics() const

uint32_t max_indentation( calc_max_indentation() );

for( auto topic : _topics_info_by_name )
for( auto & topic : _topics_info_by_name )
{
if( filter_topic( topic.first, _root ) )
continue;
Expand Down Expand Up @@ -612,11 +612,11 @@ void dds_sniffer::print_topics() const
++indentation;
}

for( auto writer : topic.second.writers )
for( auto & writer : topic.second.writers )
{
print_topic_writer( writer, max_indentation );
}
for( auto reader : topic.second.readers )
for( auto & reader : topic.second.readers )
{
print_topic_reader( reader, max_indentation );
}
Expand Down

0 comments on commit 70d4418

Please sign in to comment.