Skip to content

Cppcheck cleanup #11397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 19, 2023
Merged

Cppcheck cleanup #11397

merged 11 commits into from
Feb 19, 2023

Conversation

dmipx
Copy link
Contributor

@dmipx dmipx commented Feb 5, 2023

Fix CppCheck errors:

E uninitvar                      common/model-views.cpp+554                         Uninitialized variables: option.unset_value, option.have_unset_value, option.read_only, option.edit_mode
E uninitvar                      src/l500/l500-color.cpp+265                        Uninitialized variable: intrinsics.model
E integerOverflow                src/l500/l500-depth.cpp+322                        Signed integer overflow for expression 'baseline_address+4'.
E integerOverflow                src/l500/l500-device.cpp+321                       Signed integer overflow for expression 'ivcam2::REGISTER_CLOCK_0+4'.
E invalidContainer               common/calibration-model.cpp+347                   Using pointer to member variable '_calibration' that may be invalid.
E invalidContainer               common/calibration-model.cpp+347                   Using pointer to member variable '_original' that may be invalid.
E danglingLifetime               third-party/rsutils/include/rsutils/concurrency/concurrency.h+54 Non-local variable '_queue' will use object that points to local variable 'q'.
E danglingLifetime               third-party/rsutils/include/rsutils/concurrency/concurrency.h+55 Non-local variable '_queue' will use object that points to local variable 'q'.
E uninitStructMember             src/l500/l500-color.cpp+265                        Uninitialized struct member: intrinsics.model

@dmipx dmipx force-pushed the cppcheck-cleanup branch 3 times, most recently from 4502d27 to 8a362bf Compare February 5, 2023 16:07
@Nir-Az Nir-Az requested a review from OhadMeir February 5, 2023 16:19
@dmipx dmipx force-pushed the cppcheck-cleanup branch 3 times, most recently from 025341b to decb545 Compare February 5, 2023 18:22
k = stbi_lrot(j->code_buffer, n);
STBI_ASSERT(n >= 0 && n < (int) (sizeof(stbi__bmask)/sizeof(*stbi__bmask)));
j->code_buffer = k & ~stbi__bmask[n];
k &= stbi__bmask[n];
j->code_bits -= n;
return k + (stbi__jbias[n] & ~sgn);
return k + (stbi__jbias[n] & (sgn - 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick using -1 instead of ~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fixed issue in original source
nothings/stb@0260135

Copy link
Contributor

@OhadMeir OhadMeir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.
Getting rid of the cppcheck errors is helpful and the code logic is not always easy to follow...

@dmipx
Copy link
Contributor Author

dmipx commented Feb 6, 2023

We left with

E danglingLifetime third-party/rsutils/include/rsutils/concurrency/concurrency.h+54 Non-local variable '_queue' will use object that points to local variable 'q'.

E danglingLifetime third-party/rsutils/include/rsutils/concurrency/concurrency.h+55 Non-local variable '_queue' will use object that points to local variable 'q'.`

@dmipx dmipx requested a review from remibettan February 6, 2023 08:18
@@ -299,6 +299,8 @@ void calibration_model::update(ux_window& window, std::string& error_message)
dev.as<rs2::auto_calibrated_device>().reset_to_factory_calibration();
_calibration = dev.as<rs2::auto_calibrated_device>().get_calibration_table();
_original = _calibration;
table = (librealsense::ds::coefficients_table*)_calibration.data();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid the c-style casting, and use cpp style (static_cast or reinterpret_cast)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -444,6 +446,7 @@ void calibration_model::update(ux_window& window, std::string& error_message)
dev.as<rs2::auto_calibrated_device>().set_calibration_table(_calibration);
dev.as<rs2::auto_calibrated_device>().write_calibration();
_original = _calibration;
orig_table = (librealsense::ds::coefficients_table*)_original.data();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -523,7 +523,7 @@ namespace rs2
bool* options_invalidated,
std::string& error_message)
{
option_model option;
option_model option = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it better than before?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Ohad research looks like this zeros all native members

@@ -602,7 +602,7 @@ namespace librealsense
}

if (host_assistance == host_assistance_type::no_assistance || host_assistance == host_assistance_type::assistance_start)
_hw_monitor->send(command{ ds::AUTO_CALIB, focal_length_calib_begin, fl_step_count, fy_scan_range, p4 });
_hw_monitor->send(command{ ds::AUTO_CALIB, focal_length_calib_begin, (uint32_t)fl_step_count, (uint32_t)fy_scan_range, p4 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use static_cast here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -717,7 +717,7 @@ namespace librealsense
// Begin auto-calibration
if (host_assistance == host_assistance_type::no_assistance || host_assistance == host_assistance_type::assistance_start)
{
_hw_monitor->send(command{ ds::AUTO_CALIB, py_rx_plus_fl_calib_begin, speed_fl, 0, p4 });
_hw_monitor->send(command{ ds::AUTO_CALIB, py_rx_plus_fl_calib_begin, (uint32_t)speed_fl, 0, p4 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static_cast

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -898,7 +898,7 @@ namespace librealsense
if (depth > 0)
{
LOG_OCC_WARN("run_tare_calibration interactive control (2) with parameters: depth = " << depth);
_hw_monitor->send(command{ ds::AUTO_CALIB, interactive_scan_control, 2, depth });
_hw_monitor->send(command{ ds::AUTO_CALIB, interactive_scan_control, 2, (uint32_t)depth });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -917,7 +917,7 @@ namespace librealsense
LOG_DEBUG("run_tare_calibration with parameters: speed = " << speed << " average_step_count = " << average_step_count << " step_count = " << step_count << " accuracy = " << accuracy << " scan_parameter = " << scan_parameter << " data_sampling = " << data_sampling);
check_tare_params(speed, scan_parameter, data_sampling, average_step_count, step_count, accuracy);

auto param2 = (int)ground_truth_mm * 100;
auto param2 = (uint32_t)ground_truth_mm * 100;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -38,7 +38,7 @@ namespace librealsense
"Alternate IR cannot be enabled with IR Reflectivity" );
}

_hw_monitor->send(command{ AMCSET, _type, (int)value });
_hw_monitor->send(command{ AMCSET, (uint32_t)_type, (uint32_t)value });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -138,7 +138,7 @@ namespace librealsense
auto res = _hw_monitor->send( command{ AMCGET,
_type,
l500_command::get_default,
(int)query_sensor_mode( *_resolution ) },
(uint32_t)query_sensor_mode( *_resolution ) },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

E shiftTooManyBitsSigned         third-party/stb_image.h+1647                       Shifting signed 32-bit value by 31 bits is undefined behaviour

Use an equivalent formulation that has sgn=0 or 1, not 0 or -1.
This avoids right-shifting signed values, at least in this place.

Fixes issue IntelRealSense#1061.
nothings/stb@0260135

Signed-off-by: Dmitry Perchanov <dmitry.perchanov@intel.com>
E uninitvar                      src/l500/l500-color.cpp+265                        Uninitialized variable: intrinsics.model

Signed-off-by: Dmitry Perchanov <dmitry.perchanov@intel.com>
dmipx and others added 5 commits February 16, 2023 14:55
E uninitvar                      common/model-views.cpp+554                         Uninitialized variables: option.unset_value, option.have_unset_value, option.read_only, option.edit_mode

Signed-off-by: Dmitry Perchanov <dmitry.perchanov@intel.com>
cppcheck:
E integerOverflow                src/l500/l500-depth.cpp+322                        Signed integer overflow for expression 'baseline_address+4'.
E integerOverflow                src/l500/l500-device.cpp+321                       Signed integer overflow for expression 'ivcam2::REGISTER_CLOCK_0+4'.

l500: l500-options: msvc fix for narrowing conversion

Signed-off-by: Dmitry Perchanov <dmitry.perchanov@intel.com>
E invalidContainer               common/calibration-model.cpp+350                   Using pointer to member variable '_calibration' that may be invalid.
E invalidContainer               common/calibration-model.cpp+350                   Using pointer to member variable '_original' that may be invalid.

Signed-off-by: Dmitry Perchanov <dmitry.perchanov@intel.com>
Signed-off-by: Dmitry Perchanov <dmitry.perchanov@intel.com>
table = (librealsense::ds::coefficients_table*)_calibration.data();
orig_table = (librealsense::ds::coefficients_table*)_original.data();
table = reinterpret_cast<librealsense::ds::coefficients_table*>(_calibration.data());
orig_table = reinterpret_cast<librealsense::ds::coefficients_table*> (_original.data());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run formatting on changed lines

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

@OhadMeir OhadMeir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -176,7 +177,7 @@ namespace librealsense
// 4. Read the current value
// 5. Restore the current value
auto current = query_current( query_sensor_mode( *_resolution ) );
_hw_monitor->send( command{ AMCSET, _type, -1 } );
_hw_monitor->send( command{ AMCSET, _type, static_cast< uint32_t >( -1 ) } );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result to UINT_MAX as input (not -1) - is it ok here?

Copy link
Contributor

@remibettan remibettan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Nir-Az Nir-Az merged commit c0a5dbb into IntelRealSense:development Feb 19, 2023
@dmipx dmipx deleted the cppcheck-cleanup branch February 26, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants