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

More Coverity issues handled #12759

Merged
merged 1 commit into from
Mar 17, 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
10 changes: 5 additions & 5 deletions common/res/d415.h

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions common/res/d435.h

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions common/res/d455.h

Large diffs are not rendered by default.

60 changes: 32 additions & 28 deletions common/sw-update/http-downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,15 @@ namespace rs2
progress_data *myp = static_cast<progress_data *>(p);
CURL *curl(myp->curl);
curl_off_t curtime(0);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &curtime);
if (dltotal != 0 && (curtime - myp->last_run_time > HALF_SEC))
{
myp->last_run_time = curtime;
return myp->user_callback_func(static_cast<uint64_t>(dlnow),
static_cast<uint64_t>(dltotal)) == callback_result::CONTINUE_DOWNLOAD ? 0 : 1;
}
else
{
return 0;
}
if( curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME_T, &curtime) == CURLE_OK )
if (dltotal != 0 && (curtime - myp->last_run_time > HALF_SEC))
{
myp->last_run_time = curtime;
return myp->user_callback_func(static_cast<uint64_t>(dlnow),
static_cast<uint64_t>(dltotal)) == callback_result::CONTINUE_DOWNLOAD ? 0 : 1;
}

return 0;
}

http_downloader::http_downloader() : _curl(nullptr)
Expand All @@ -127,10 +125,11 @@ namespace rs2
if (!_curl) return false;

set_common_options(url);
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, stream_write_callback);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &output);
curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYPEER ,0L);
curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYHOST ,0L);
if( curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, stream_write_callback) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &output) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYPEER ,0L) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_SSL_VERIFYHOST ,0L) != CURLE_OK )
throw std::invalid_argument( "Setting CURL option failed" );

progress_data progress_record; // Should stay here - "curl_easy_perform" use it
if (user_callback_func)
Expand All @@ -152,8 +151,9 @@ namespace rs2
if (!_curl) return false;

set_common_options(url);
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, vector_write_callback);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &output);
if( curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, vector_write_callback) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &output) != CURLE_OK )
throw std::invalid_argument( "Setting CURL option failed" );

progress_data progress_record; // Should stay here - "curl_easy_perform" use it
if (user_callback_func)
Expand Down Expand Up @@ -181,8 +181,9 @@ namespace rs2
if (out_file.good())
{
set_common_options(url);
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, file_write_callback);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &out_file);
if( curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, file_write_callback) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, &out_file) != CURLE_OK )
throw std::invalid_argument( "Setting CURL option failed" );

progress_data progress_record; // Should stay here - "curl_easy_perform" use it
if (user_callback_func)
Expand All @@ -209,19 +210,22 @@ namespace rs2

void http_downloader::set_common_options(const std::string &url)
{
curl_easy_setopt(_curl, CURLOPT_URL, url.c_str()); // provide the URL to use in the request
curl_easy_setopt(_curl, CURLOPT_FOLLOWLOCATION, 1L); // follow HTTP 3xx redirects
curl_easy_setopt(_curl, CURLOPT_NOSIGNAL, 1); // skip all signal handling
curl_easy_setopt(_curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT); // timeout for the connect phase
curl_easy_setopt(_curl, CURLOPT_FAILONERROR, 1L); // request failure on HTTP response >= 400
curl_easy_setopt(_curl, CURLOPT_NOPROGRESS, 1L); // switch off the progress meter
if( curl_easy_setopt( _curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT ) != CURLE_OK || // timeout for the connect phase
curl_easy_setopt( _curl, CURLOPT_URL, url.c_str() ) != CURLE_OK || // provide the URL to use in the request
curl_easy_setopt( _curl, CURLOPT_FOLLOWLOCATION, 1L ) != CURLE_OK || // follow HTTP 3xx redirects
curl_easy_setopt( _curl, CURLOPT_NOSIGNAL, 1 ) != CURLE_OK || // skip all signal handling
curl_easy_setopt( _curl, CURLOPT_FAILONERROR, 1L ) != CURLE_OK || // request failure on HTTP response >= 400
curl_easy_setopt( _curl, CURLOPT_NOPROGRESS, 1L ) != CURLE_OK ) // switch off the progress meter
throw std::invalid_argument( "Setting CURL option failed" );
}

void http_downloader::register_progress_call_back(progress_data &progress_record, user_callback_func_type user_callback_func)
{
progress_record = { 0, user_callback_func, _curl };
curl_easy_setopt(_curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
curl_easy_setopt(_curl, CURLOPT_XFERINFODATA, &progress_record);
curl_easy_setopt(_curl, CURLOPT_NOPROGRESS, 0L);
if( curl_easy_setopt(_curl, CURLOPT_XFERINFOFUNCTION, progress_callback) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_XFERINFODATA, &progress_record) != CURLE_OK ||
curl_easy_setopt(_curl, CURLOPT_NOPROGRESS, 0L) != CURLE_OK )
throw std::invalid_argument( "Setting CURL option failed" );
}
#endif
}
Expand Down
10 changes: 8 additions & 2 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,14 @@ namespace rs2

end_frame();

rs2::gl::shutdown_rendering();
if (_use_glsl_proc) rs2::gl::shutdown_processing();
try
{
rs2::gl::shutdown_rendering();
if (_use_glsl_proc) rs2::gl::shutdown_processing();
}
catch( ... )
{
}

ImGui::GetIO().Fonts->ClearFonts(); // To be refactored into Viewer theme object
ImGui_ImplGlfw_Shutdown();
Expand Down
1 change: 1 addition & 0 deletions examples/software-device/rs-software-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class custom_frame_source
}
}
color_frame.frame = std::move(pixels_color);
stbi_image_free( realsense_logo );
}

synthetic_frame& get_synthetic_texture()
Expand Down
13 changes: 5 additions & 8 deletions tools/depth-quality/depth-quality-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,15 +625,12 @@ namespace rs2
bool allow_changing_roi = true;
try
{
if (_depth_sensor_model)
auto && ds = _depth_sensor_model->dev.first<depth_sensor>();
if( ds.supports( RS2_OPTION_ENABLE_IR_REFLECTIVITY )
&& ( ds.get_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY ) == 1.0f ) )
{
auto && ds = _depth_sensor_model->dev.first<depth_sensor>();
if( ds.supports( RS2_OPTION_ENABLE_IR_REFLECTIVITY )
&& ( ds.get_option( RS2_OPTION_ENABLE_IR_REFLECTIVITY ) == 1.0f ) )
{
allow_changing_roi = false;
_error_message = "ROI cannot be changed while IR Reflectivity is enabled";
}
allow_changing_roi = false;
_error_message = "ROI cannot be changed while IR Reflectivity is enabled";
}
}
catch (...) {}
Expand Down
9 changes: 5 additions & 4 deletions tools/embed/rs-embed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ int main(int argc, char** argv) try
// compress szSource into pchCompressed
auto rawDataSize = (int)data.size();
auto compressBufSize = LZ4_compressBound(rawDataSize);
char* pchCompressed = new char[compressBufSize];
memset(pchCompressed, 0, compressBufSize);
auto four_byte_mul_size = compressBufSize + ( 4 - compressBufSize % 4 );
char * pchCompressed = new char[four_byte_mul_size];
memset( pchCompressed, 0, four_byte_mul_size );
int nCompressedSize = LZ4_compress_default((const char*)data.data(), pchCompressed, rawDataSize, compressBufSize);


Expand All @@ -169,7 +170,7 @@ int main(int argc, char** argv) try

auto nAllignedCompressedSize = nCompressedSize;
auto leftover = nCompressedSize % 4;
if (leftover % 4 != 0) nAllignedCompressedSize += (4 - leftover);
nAllignedCompressedSize += (4 - leftover);

for (int i = 0; i < nAllignedCompressedSize; i += 4)
{
Expand All @@ -186,7 +187,7 @@ int main(int argc, char** argv) try
myfile << "inline void uncompress_" << name << "_obj(std::vector<float3>& vertex_data, std::vector<float3>& normals, std::vector<short3>& index_data)\n";
myfile << "{\n";
myfile << " std::vector<char> uncompressed(0x" << std::hex << rawDataSize << ", 0);\n";
myfile << " LZ4_decompress_safe((const char*)" << name << "_obj_data, uncompressed.data(), 0x" << std::hex << nCompressedSize << ", 0x" << std::hex << rawDataSize << ");\n";
myfile << " (void)LZ4_decompress_safe((const char*)" << name << "_obj_data, uncompressed.data(), 0x" << std::hex << nCompressedSize << ", 0x" << std::hex << rawDataSize << ");\n";
myfile << " const int vertex_size = 0x" << std::hex << vertex_data.size() << " * sizeof(float3);\n";
myfile << " const int index_size = 0x" << std::hex << index_data.size() << " * sizeof(short3);\n";
myfile << " vertex_data.resize(0x" << std::hex << vertex_data.size() << ");\n";
Expand Down
Loading