Election-Tech-Initiative / electionguard-cpp

A C++ implementation of ElectionGuard specification focused on encryption components.
https://www.electionguard.vote/
MIT License
23 stars 26 forks source link

🧹 Resolve build warning: C4035 Truncation #217

Closed keithrfung closed 2 years ago

keithrfung commented 3 years ago

Is there an existing issue for this?

Suggestion

Resolve C4305 error surrounding truncation.

These can be seen in this example run under windows-2019-gcc-9.2.0 or windows-2019-msvc-latest.

Example:

warning C4305: 'return': truncation from 'eg_electionguard_status_e' to 'bool' [D:\a\electionguard-cpp\electionguard-cpp\build\libs\msvc\Win32\src\electionguard.vcxproj]

Possible Implementation

No response

Anything else?

MSDocs: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4305?view=msvc-160

avinal commented 3 years ago

Hey @keithrfung , I doubt the logic of the code.

Here the function eg_ciphertext_ballot_selection_is_valid_encryption() checks for valid encryption. If I am not wrong, then the function must return false if the return type is bool, or a non-zero value indicating a specific error if return type is int.

https://github.com/microsoft/electionguard-cpp/blob/a29c8b4a2be1c2424593649e3dc68799f64af718/src/electionguard/facades/ballot.cpp#L333-L336

But here the return type is bool, and if an exception occurs then the function will return 5 (a non-zero due to enum type) and it will be considered true. Please correct me, if I have misinterpreted anything.

keithrfung commented 3 years ago

I'm going to let @AddressXception follow up on this one.

AddressXception commented 3 years ago

yes this is a bug. let's slot it into the next release.

SteveMaier-IRT commented 2 years ago

Matt already fixed this code.