-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Cppcheck cleanup #11397
Conversation
4502d27
to
8a362bf
Compare
025341b
to
decb545
Compare
third-party/stb_image.h
Outdated
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)); |
There was a problem hiding this comment.
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 ~
There was a problem hiding this comment.
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
There was a problem hiding this 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...
decb545
to
be54117
Compare
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'.` |
common/calibration-model.cpp
Outdated
@@ -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(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
common/calibration-model.cpp
Outdated
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
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 = {}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/ds/ds5/ds5-auto-calibration.cpp
Outdated
@@ -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 }); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/ds/ds5/ds5-auto-calibration.cpp
Outdated
@@ -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 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static_cast
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/ds/ds5/ds5-auto-calibration.cpp
Outdated
@@ -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 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/ds/ds5/ds5-auto-calibration.cpp
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/l500/l500-options.cpp
Outdated
@@ -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 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/l500/l500-options.cpp
Outdated
@@ -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 ) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
d6f1184
to
f7b7913
Compare
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>
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>
common/calibration-model.cpp
Outdated
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
1cac4f7
to
de67617
Compare
There was a problem hiding this 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 ) } ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fix CppCheck errors: