LoupVaillant / Monocypher

An easy to use, easy to deploy crypto library
https://monocypher.org
Other
614 stars 80 forks source link

Does not compile under Visual Studio 2019 #169

Closed peirick closed 4 years ago

peirick commented 4 years ago

In file monocypher.c line 2684 gives the following error:

monocypher.c(2683,27): error C4146: unary minus operator applied to unsigned type, result still unsigned

see also C4146

fscoto commented 4 years ago

That particular line is u32 mask = (u32)-carry; // carry == 0 or 1. In this case, the error is completely spurious because the behavior this warns about is exactly what the code trying to do:

carry mask
0 0 == (u32)-0
1 0xffffffff == (u32)-1

There's probably a workaround to be found here other than overriding that particular error for monocypher.c if possible (something like ((u32)~carry) + 1 maybe? It's likely missing some more casts and/or can be safely simplified in some manner). As far as I'm aware, unary negation of an unsigned integer is well-defined and shouldn't be an error, so this is probably VS2019 being overzealous (or the C++ standard disagreeing with C).

Probably needs @LoupVaillant's attention. Personally, I'd be fine using a workaround and avoiding unsigned negation for scared, but his mileage may vary. Note for Loup: The workaround above compiles under VS2019 without warning for me and appears to work as intended.

tankf33der commented 4 years ago

The workaround above compiles under VS2019 without warning for me and appears to work as intended.

@fscoto — What about tests with patch under VS2019? Passed, right?

fscoto commented 4 years ago

They're in the same state of breakage with and without it, cf. #170.

LoupVaillant commented 4 years ago

Hi, thanks for the report. Should work better now.