Skip to content
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

Coverity & rs-dds-config fix #13338

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 1 deletion third-party/rsutils/include/rsutils/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class signal
}

// How many subscriptions are active
size_t size() const { return _impl->subscribers.size(); }
size_t size() const
{
std::lock_guard< std::mutex > locker( _impl->mutex );
return _impl->subscribers.size();
}
};


Expand Down
10 changes: 7 additions & 3 deletions third-party/rsutils/src/network-adapter-watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,14 @@ class network_adapter_watcher_singleton
#else
if( _th.joinable() )
{
if( write( _done, &_done, sizeof( &_done ) ) != sizeof( &_done ) )
/* to avoid compiler warning about not using return value */;
_th.join();
uint64_t incr = 1; // must be 8-byte integer value
auto rv = write( _done, &incr, sizeof( incr ) );
if( rv != sizeof( incr ) )
LOG_WARNING( "failed to write to network adapter watcher done event: " << rv );
else
_th.join();
Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't join, it will cause program abnormal termination. Maybe retry to signal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just to avoid a hang if the write fails (it failed and hung); it's not expected once done right (and now it is)

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, if write fails it's probably an OS error and it means we won't close gracefully. I think it's acceptable.

}
close( _socket );
close( _done );
#endif
}
Expand Down
1 change: 1 addition & 0 deletions tools/dds/dds-config/rs-dds-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ try
bool const golden = golden_arg.isSet();

// Create a RealSense context and look for a device
settings["dds"]["enabled"] = true;
rs2::context ctx( settings.dump() );

rs2::device device;
Expand Down
Loading