-
Notifications
You must be signed in to change notification settings - Fork 477
fix compile warnings in lib/ #6260
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR addresses various compiler warnings on Linux g++ 11.4.0 by introducing explicit casts and replacing unsafe functions with their safer counterparts (e.g. snprintf in place of sprintf). Key changes include:
- Adding explicit type casts to suppress warnings regarding numeric conversions.
- Increasing buffer sizes where needed and standardizing type conversions.
- Updating return types and comparisons to use more appropriate integer types.
Reviewed Changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
lib/util.cpp | Replaced sprintf with snprintf and added explicit casts in time and string functions. |
lib/url.cpp | Added explicit cast for atol conversion and improved character arithmetic safety. |
lib/str_util.cpp | Changed implicit casts in time conversion to explicit casts. |
lib/procinfo_unix.cpp | Ensured correct type conversion for memory and timing values. |
lib/parse.h & lib/parse.cpp | Updated type casts when converting long values to int. |
lib/opencl_boinc.cpp | Added explicit casts for unsigned conversion and floor() output. |
lib/msg_queue.cpp | Changed variable types for msgrcv() to reflect its return type. |
lib/mem_usage.cpp | Cast the result of fread to int. |
lib/gui_rpc_client(.cpp) | Updated port conversions using explicit casts and ensured consistent type usage. |
lib/filesys.cpp | Converted file copy sizes to size_t and introduced explicit casts during comparisons. |
lib/diagnostics.cpp | Added explicit casts in stack trace printing functions. |
lib/crypt_prog.cpp & lib/crypt.cpp | Applied explicit casts for key length and data conversions. |
lib/coproc.cpp | Added explicit casts for memory size conversions. |
lib/boinc_stdio.h | Updated ftell() return type from int to long. |
Files not reviewed (2)
- client/Makefile.linux: Language not supported
- lib/Makefile.linux: Language not supported
char buf[2048], url_buf[512], wu_buf[512]; | ||
|
||
safe_strcpy(url_buf, proj_url_esc); | ||
downcase_string(url_buf); | ||
safe_strcpy(wu_buf, wu_name); | ||
downcase_string(wu_buf); | ||
|
||
sprintf(buf, "boinc__%s__%s", url_buf, wu_buf); | ||
snprintf(buf, sizeof(buf), "boinc__%s__%s", url_buf, wu_buf); | ||
return string(buf); |
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.
Ensure that the increased size for 'buf' and the reduced sizes for 'url_buf' and 'wu_buf' are sufficient for all expected inputs to avoid potential buffer truncation or overflow.
Copilot uses AI. Check for mistakes.
@@ -1111,11 +1111,11 @@ int read_file_malloc(const char* path, char*& buf, size_t max_len, bool tail) { | |||
if (!f) return ERR_FOPEN; | |||
|
|||
#ifndef _USING_FCGI_ | |||
if (max_len && size > max_len) { | |||
if (max_len && size > (double)max_len) { |
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.
Using a double conversion for 'max_len' in the size comparison may lead to precision issues; consider using an integer type to ensure consistent behavior.
if (max_len && size > (double)max_len) { | |
if (max_len && size > max_len) { |
Copilot uses AI. Check for mistakes.
@davidpanderson, ssize_t is not from C standard but from the POSIX. Visual Studio is not 100% POSIX-compatible |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6260 +/- ##
=========================================
Coverage 11.94% 11.95%
Complexity 1068 1068
=========================================
Files 278 278
Lines 36967 36971 +4
Branches 8541 8542 +1
=========================================
+ Hits 4416 4419 +3
Misses 32150 32150
- Partials 401 402 +1
🚀 New features to boost your workflow:
|
In lib/, fix warnings with Linux g++ version 11.4.0, using the compiler options listed here:
https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html
(except for the RSA deprecation warnings, which appear even with -Wno-deprecated)
Note: it's pretty much all type casting.
In many cases this could also be eliminated by using the right types in the first place,
e.g. size_t instead of int in various places.