Skip to content

Commit

Permalink
fix High Coverity issues
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Sep 12, 2024
1 parent 0a14c4e commit b9cc8ae
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 62 deletions.
30 changes: 8 additions & 22 deletions examples/C/color/rs-color.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved.

/* Include the librealsense C header files */
#include <librealsense2/rs.h>
Expand All @@ -15,12 +15,12 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// These parameters are reconfigurable //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define STREAM RS2_STREAM_COLOR // rs2_stream is a types of data provided by RealSense device //
#define FORMAT RS2_FORMAT_RGB8 // rs2_format identifies how binary data is encoded within a frame //
#define WIDTH 640 // Defines the number of columns for each frame //
#define HEIGHT 480 // Defines the number of lines for each frame //
#define FPS 30 // Defines the rate of frames per second //
#define STREAM_INDEX 0 // Defines the stream index, used for multiple streams of the same type //
#define STREAM RS2_STREAM_COLOR // Type of data provided by RealSense device //
#define FORMAT RS2_FORMAT_ANY // How binary data is encoded within a frame (ANY) //
#define WIDTH 0 // Number of columns for each frame (ANY) //
#define HEIGHT 0 // Number of lines for each frame (ANY) //
#define FPS 0 // Rate of frames per second (ANY) //
#define STREAM_INDEX -1 // Used for multiple streams of the same type (ANY) //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -74,7 +74,7 @@ int main()
exit(EXIT_FAILURE);
}

while (1)
while (1) // Until user presses Ctrl+C
{
// This call waits until a new composite_frame is available
// composite_frame holds a set of frames. It is used to prevent frame drops
Expand Down Expand Up @@ -125,18 +125,4 @@ int main()

rs2_release_frame(frames);
}

// Stop the pipeline streaming
rs2_pipeline_stop(pipeline, &e);
check_error(e);

// Release resources
rs2_delete_pipeline_profile(pipeline_profile);
rs2_delete_config(config);
rs2_delete_pipeline(pipeline);
rs2_delete_device(dev);
rs2_delete_device_list(device_list);
rs2_delete_context(ctx);

return EXIT_SUCCESS;
}
21 changes: 2 additions & 19 deletions examples/C/depth/rs-depth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved.

/* Include the librealsense C header files */
#include <librealsense2/rs.h>
Expand Down Expand Up @@ -159,7 +159,7 @@ int main()
char* buffer = calloc(display_size, sizeof(char));
char* out = NULL;

while (1)
while (1) // Until user presses Ctrl+C
{
// This call waits until a new composite_frame is available
// composite_frame holds a set of frames. It is used to prevent frame drops
Expand Down Expand Up @@ -227,21 +227,4 @@ int main()

rs2_release_frame(frames);
}

// Stop the pipeline streaming
rs2_pipeline_stop(pipeline, &e);
check_error(e);

// Release resources
free(buffer);
rs2_delete_pipeline_profile(pipeline_profile);
rs2_delete_stream_profiles_list(stream_profile_list);
rs2_delete_stream_profile(stream_profile);
rs2_delete_config(config);
rs2_delete_pipeline(pipeline);
rs2_delete_device(dev);
rs2_delete_device_list(device_list);
rs2_delete_context(ctx);

return EXIT_SUCCESS;
}
18 changes: 2 additions & 16 deletions examples/C/distance/rs-distance.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
// Copyright(c) 2017-24 Intel Corporation. All Rights Reserved.

/* Include the librealsense C header files */
#include <librealsense2/rs.h>
Expand Down Expand Up @@ -75,7 +75,7 @@ int main()
exit(EXIT_FAILURE);
}

while (1)
while (1) // Until user presses Ctrl+C
{
// This call waits until a new composite_frame is available
// composite_frame holds a set of frames. It is used to prevent frame drops
Expand Down Expand Up @@ -117,18 +117,4 @@ int main()

rs2_release_frame(frames);
}

// Stop the pipeline streaming
rs2_pipeline_stop(pipeline, &e);
check_error(e);

// Release resources
rs2_delete_pipeline_profile(pipeline_profile);
rs2_delete_config(config);
rs2_delete_pipeline(pipeline);
rs2_delete_device(dev);
rs2_delete_device_list(device_list);
rs2_delete_context(ctx);

return EXIT_SUCCESS;
}
16 changes: 12 additions & 4 deletions src/global_timestamp_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,18 @@ namespace librealsense
sum_xy += (crnt_sample._x * crnt_sample._y);
sum_x2 += (crnt_sample._x * crnt_sample._x);
}
b = (sum_y*sum_x2 - sum_x * sum_xy) / (n*sum_x2 - sum_x * sum_x);
a = (n*sum_xy - sum_x * sum_y) / (n*sum_x2 - sum_x * sum_x);

if (_last_request_time - _prev_time < _time_span_ms)
double denom = n * sum_x2 - sum_x * sum_x;
if( denom > std::numeric_limits< double >::epsilon() )
{
b = (sum_y * sum_x2 - sum_x * sum_xy) / denom;
a = (n * sum_xy - sum_x * sum_y) / denom;
}
else
{
a = _dest_a;
b = _dest_b;
}
if( _last_request_time - _prev_time < _time_span_ms )
{
dt = (_last_request_time - _prev_time) / _time_span_ms;
}
Expand Down
3 changes: 2 additions & 1 deletion third-party/rsutils/src/network-adapter-watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ class network_adapter_watcher_singleton
#else
if( _th.joinable() )
{
if( write( _done, &_done, sizeof( &_done ) ) != sizeof( &_done ) )
if( write( _done, &_done, sizeof( _done ) ) != sizeof( _done ) )
/* to avoid compiler warning about not using return value */;
_th.join();
}
close( _socket );
close( _done );
#endif
}
Expand Down

0 comments on commit b9cc8ae

Please sign in to comment.