Skip to content

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

fix compile warnings in lib/ #6260

wants to merge 9 commits into from

Conversation

davidpanderson
Copy link
Contributor

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.

@Copilot Copilot AI review requested due to automatic review settings April 18, 2025 02:53
Copy link
Contributor

@Copilot Copilot AI left a 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

Comment on lines +824 to 832
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);
Copy link
Preview

Copilot AI Apr 18, 2025

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) {
Copy link
Preview

Copilot AI Apr 18, 2025

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.

Suggested change
if (max_len && size > (double)max_len) {
if (max_len && size > max_len) {

Copilot uses AI. Check for mistakes.

@AenBleidd
Copy link
Member

@davidpanderson, ssize_t is not from C standard but from the POSIX. Visual Studio is not 100% POSIX-compatible

Copy link

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 37.14286% with 44 lines in your changes missing coverage. Please review.

Project coverage is 11.95%. Comparing base (29ef4a9) to head (07faf25).

Files with missing lines Patch % Lines
lib/gui_rpc_client.cpp 0.00% 6 Missing ⚠️
lib/parse.cpp 33.33% 6 Missing ⚠️
lib/coproc.cpp 0.00% 5 Missing ⚠️
lib/procinfo_unix.cpp 0.00% 5 Missing ⚠️
lib/diagnostics.cpp 0.00% 4 Missing ⚠️
lib/util.cpp 20.00% 4 Missing ⚠️
lib/filesys.cpp 0.00% 3 Missing ⚠️
lib/opencl_boinc.cpp 0.00% 3 Missing ⚠️
lib/crypt.cpp 81.81% 2 Missing ⚠️
lib/gui_rpc_client_print.cpp 0.00% 2 Missing ⚠️
... and 3 more
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     
Files with missing lines Coverage Δ
lib/boinc_stdio.h 20.40% <ø> (ø)
lib/crypt_prog.cpp 60.40% <100.00%> (ø)
lib/str_util.cpp 58.00% <100.00%> (ø)
lib/mem_usage.cpp 0.00% <0.00%> (ø)
lib/url.cpp 87.42% <90.90%> (-0.33%) ⬇️
lib/crypt.cpp 54.38% <81.81%> (ø)
lib/gui_rpc_client_print.cpp 0.00% <0.00%> (ø)
lib/parse.h 61.90% <0.00%> (ø)
lib/filesys.cpp 0.00% <0.00%> (ø)
lib/opencl_boinc.cpp 0.00% <0.00%> (ø)
... and 6 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

2 participants