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

C++ code: eliminate a source of potential bugs #5771

Merged
merged 1 commit into from
Aug 20, 2024
Merged

Conversation

davidpanderson
Copy link
Contributor

To create zero-filled structs, we use a method where we create a static struct using a 'dummy constructor' taking an (unused) int argument. The problem is that if you mistakenly have e.g.
COPROC c = 1;
you don't get a compile error;
you get an uninitialized struct as if you had done
COPROC c = COPROC(1);
I changed this so that we use a type DUMMY_TYPE
(guaranteed not to be convertible from anything)
as the arg type for the dummy constructors.
So now you get a compile error in the above case.

To create zero-filled structs, we use a method where we create
a static struct using a 'dummy constructor' taking an (unused) int argument.
The problem is that if you mistakenly have e.g.
    COPROC c = 1;
you don't get a compile error;
you get an uninitialized struct as if you had done
    COPROC c = COPROC(1);
I changed this so that we use a type DUMMY_TYPE
(guaranteed not to be convertible from anything)
as the arg type for the dummy constructors.
So now you get a compile error in the above case.
Copy link

codecov bot commented Aug 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 10.51%. Comparing base (7d7c218) to head (fd573a7).
Report is 2 commits behind head on master.

Files Patch % Lines
lib/coproc.h 0.00% 2 Missing ⚠️
lib/prefs.h 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #5771   +/-   ##
=========================================
  Coverage     10.51%   10.51%           
  Complexity     1068     1068           
=========================================
  Files           279      279           
  Lines         35956    35956           
  Branches       8440     8440           
=========================================
  Hits           3780     3780           
  Misses        31782    31782           
  Partials        394      394           
Files Coverage Δ
lib/common_defs.h 0.00% <ø> (ø)
lib/opencl_boinc.h 0.00% <ø> (ø)
lib/prefs.h 0.00% <0.00%> (ø)
lib/coproc.h 0.00% <0.00%> (ø)

@AenBleidd AenBleidd added this to the Client/Manager 8.0.5 milestone Aug 20, 2024
@AenBleidd AenBleidd merged commit cb8684b into master Aug 20, 2024
145 of 146 checks passed
@AenBleidd AenBleidd deleted the dpa_dummy_const branch August 20, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

2 participants