LoupVaillant / Monocypher

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

Warnings and errors when compiling using MSVC 2017 #93

Closed kareldonk closed 6 years ago

kareldonk commented 6 years ago

I get the following warnings and errors when compiling using Microsoft Visual C/C++ 2017.

monocypher.c(64): warning C4244: 'function': conversion from 'u64' to 'u32', possible loss of data monocypher.c(240): error C4146: unary minus operator applied to unsigned type, result still unsigned monocypher.c(329): warning C4244: '=': conversion from 'const u64' to 'uint32_t', possible loss of data monocypher.c(314): warning C4244: 'initializing': conversion from 'const u64' to 'const u32', possible loss of data monocypher.c(381): error C4146: unary minus operator applied to unsigned type, result still unsigned monocypher.c(432): warning C4244: 'function': conversion from 'const u64' to 'u32', possible loss of data monocypher.c(433): warning C4244: 'function': conversion from 'const u64' to 'u32', possible loss of data monocypher.c(434): warning C4244: 'function': conversion from 'const u64' to 'u32', possible loss of data monocypher.c(435): warning C4244: 'function': conversion from 'const u64' to 'u32', possible loss of data monocypher.c(587): error C4146: unary minus operator applied to unsigned type, result still unsigned monocypher.c(948): warning C4267: 'function': conversion from 'size_t' to 'u32', possible loss of data monocypher.c(954): warning C4267: 'initializing': conversion from 'size_t' to 'u32', possible loss of data monocypher.c(955): warning C4267: 'initializing': conversion from 'size_t' to 'u32', possible loss of data monocypher.c(958): warning C4267: 'initializing': conversion from 'size_t' to 'u32', possible loss of data monocypher.c(1052): warning C4244: '=': conversion from 'i64' to 'i32', possible loss of data monocypher.c(1062): warning C4244: '=': conversion from 'i64' to 'i32', possible loss of data monocypher.c(1118): warning C4244: '=': conversion from 'i64' to 'i32', possible loss of data monocypher.c(1152): warning C4244: '=': conversion from 'i64' to 'i32', possible loss of data monocypher.c(1714): error C4146: unary minus operator applied to unsigned type, result still unsigned monocypher.c(1758): error C4146: unary minus operator applied to unsigned type, result still unsigned

Due to the errors compilation fails with MSVC. Perhaps you might want to check this for a future release.

LoupVaillant commented 6 years ago

I'll correct those, thanks. Error C4146 might be a problem, though. First, I am pretty astonished this is an error, and not just a warning. Second, isnt't negation of unsigned integers perfectly defined and portable?

kareldonk commented 6 years ago

Depending on the MSVC compiler settings (security option turned on) C4146 becomes an error instead of a warning (MSDN doc). It depends on what you're doing and where you're using it. So if you are absolutely sure it's not an issue where you're using it, you can turn the warning/error off in your code. The same goes for the other warnings. To turn off warnings for the whole file or just a line of code, you can use the info on MSDN here.

LoupVaillant commented 6 years ago

Well, I do have a cheap workaround that should generate the same code. Instead of writing -x & 63, I could write (~x + 1) & 63. Not very readable, though, maybe I should factor it into a function.

LoupVaillant commented 6 years ago

I've just pushed an update to deal with those warnings and errors. Does it get rid of everything?

mikejsavage commented 6 years ago

First, I am pretty astonished this is an error, and not just a warning.

MSVC on max warnings is mad, even the standard headers don't build cleanly with it :d

kareldonk commented 6 years ago

The code compiles cleanly now with no warnings and errors @LoupVaillant. Thanks!

LoupVaillant commented 6 years ago

Nice! I'm closing this, thanks for the report.