Message ID | 20220824165718.102002-1-arne@rfc2549.org |
---|---|
State | Accepted |
Headers | show |
Series | [Openvpn-devel] Fix delcarion of pubkeys in test_provider.c in MSVC builds | expand |
Typo "delcarion" in summary line On Wed, Aug 24, 2022 at 06:57:18PM +0200, Arne Schwabe wrote: > Error: test_provider.c(74): error C2099: initializer is not a constant > > Fix this issue by making the const char* to const char[]. This is probably > of one the weird array decay corner cases > > I could not find another/better way around this issue. Godbolt link to try: > > https://godbolt.org/z/s3aPb9q8q Do we really need that link here? > This error only occurs when building unit tests with windows which our Probably better MSVC instead of Windows. Or "MSVC on Windows". > normal build system does not do but my out of tree cmake build script > tries and fails Actual change is trivial so Acked-By: Frank Lichtenheld <frank@lichtenheld.com> Regards,
Hi, On Wed, Aug 24, 2022 at 06:57:18PM +0200, Arne Schwabe wrote: > Error: test_provider.c(74): error C2099: initializer is not a constant > > Fix this issue by making the const char* to const char[]. This is probably > of one the weird array decay corner cases Out of curiosity - does the error go away if you just remove all these "const" from the declaration? Making this just a "static char *"? gert
Hi, On Thu, Aug 25, 2022 at 10:36:21PM +0200, Gert Doering wrote: > On Wed, Aug 24, 2022 at 06:57:18PM +0200, Arne Schwabe wrote: > > Error: test_provider.c(74): error C2099: initializer is not a constant > > > > Fix this issue by making the const char* to const char[]. This is probably > > of one the weird array decay corner cases > > Out of curiosity - does the error go away if you just remove all these > "const" from the declaration? Making this just a "static char *"? Ah, I see the problem. Unrelated to those "consts", but technically, char * a = "foo" is a pointer variable initialized with the memory location of "foo", while char b[] = "foo" is an array. *Usage* in C is synonymous, because "a" will get the address stored in the pointer variable, while "b" will just give us the memory location, both being "the memory location where "foo" is stored". Usage in a compile time initialization is indeed different, as char *c[] = { a, b }; would strictly speaking need to load the value of "a" here... which should work at runtime, inside a function, but seemingly not with all compilers at compile time for a static global. Interesting :-) gert
I have removed the godbolt reference, and fixed "declaration" :-) - the godbolt thing is not truly relevant in git history, but can be found via the URL: when going to the discussion (if someone is really interested) Your patch has been applied to the master branch. commit 7286a7e1a23146607ce94841afae8b1f4b75859e Author: Arne Schwabe Date: Wed Aug 24 18:57:18 2022 +0200 Fix declaration of pubkeys in test_provider.c in MSVC builds Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Frank Lichtenheld <frank@lichtenheld.com> Message-Id: <20220824165718.102002-1-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25102.html Signed-off-by: Gert Doering <gert@greenie.muc.de> -- kind regards, Gert Doering
On Thu, Aug 25, 2022 at 4:37 PM Gert Doering <gert@greenie.muc.de> wrote: > Hi, > > On Wed, Aug 24, 2022 at 06:57:18PM +0200, Arne Schwabe wrote: > > Error: test_provider.c(74): error C2099: initializer is not a constant > > > > Fix this issue by making the const char* to const char[]. This is > probably > > of one the weird array decay corner cases > > Out of curiosity - does the error go away if you just remove all these > "const" from the declaration? Making this just a "static char *"? > The const after * in the original was to make the pointer a compile-time constant and usable as an initializer. Else even gcc and clang will error out. The const before * indicating the value is a constant could be removed, but the value is in fact a constant string literal, so why do so.... Anyway, for some reason MSVC doesn't seem to accept any form other than what Arne proposed. Unless we define pubkeys[] using the three string literals directly and eliminate those intermediate vars (pubkey1, 2, 3). . Selva
diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/openvpn/test_provider.c index 3f9a26e57..9451a6e7e 100644 --- a/tests/unit_tests/openvpn/test_provider.c +++ b/tests/unit_tests/openvpn/test_provider.c @@ -52,24 +52,24 @@ static int mgmt_callback_called; static OSSL_PROVIDER *prov[2]; /* public keys for testing -- RSA and EC */ -static const char *const pubkey1 = "-----BEGIN PUBLIC KEY-----\n" - "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7GWP6RLCGlvmVioIqYI6\n" - "LUR4owA7sJ/nJxBAk+/xzD6gqgSigBsTqeb+gdZwkKjY1N4w2DUA0r5i8Eja/BWN\n" - "xMZtC5nxK4MACtMqIwvlzfk130NhFXKtlZj2cyFBXqDdRyeg1ZrUQagcHVcgcReP\n" - "9yiePgfO7NUOQk8edEeOR53SFCgnLBQQ9dGWtZN0hO/5BN6NSm/fd6vq0VjTRP5a\n" - "BAH/BnqX9/3jV0jh8N9AE59mI1rjVVQ9VDnuAPkS8dLfdC661/CNxt0YWByTIgt1\n" - "+qjW4LUvLbnU/rlPhuJ1SBZg+z/JtDBCKfs7syu5WYFqRvNFg7/91Rr/NwxvW/1h\n" - "8QIDAQAB\n" - "-----END PUBLIC KEY-----\n"; - -static const char *const pubkey2 = "-----BEGIN PUBLIC KEY-----\n" - "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEO85iXW+HgnUkwlj1DohNVw0GsnGIh1gZ\n" - "u95ff1JiUaJIkYNIkZA+hwIPFVH5aJcSCv3SPIeDS2VUAESNKHZJBQ==\n" - "-----END PUBLIC KEY-----\n"; - -static const char *const pubkey3 = "-----BEGIN PUBLIC KEY-----\n" - "MCowBQYDK2VwAyEA+q5xjF5hGyyqYZidJdz/0saEQabL3N4wIZJBxNGbgJE=\n" - "-----END PUBLIC KEY-----"; +static const char pubkey1[] = "-----BEGIN PUBLIC KEY-----\n" + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7GWP6RLCGlvmVioIqYI6\n" + "LUR4owA7sJ/nJxBAk+/xzD6gqgSigBsTqeb+gdZwkKjY1N4w2DUA0r5i8Eja/BWN\n" + "xMZtC5nxK4MACtMqIwvlzfk130NhFXKtlZj2cyFBXqDdRyeg1ZrUQagcHVcgcReP\n" + "9yiePgfO7NUOQk8edEeOR53SFCgnLBQQ9dGWtZN0hO/5BN6NSm/fd6vq0VjTRP5a\n" + "BAH/BnqX9/3jV0jh8N9AE59mI1rjVVQ9VDnuAPkS8dLfdC661/CNxt0YWByTIgt1\n" + "+qjW4LUvLbnU/rlPhuJ1SBZg+z/JtDBCKfs7syu5WYFqRvNFg7/91Rr/NwxvW/1h\n" + "8QIDAQAB\n" + "-----END PUBLIC KEY-----\n"; + +static const char pubkey2[] = "-----BEGIN PUBLIC KEY-----\n" + "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEO85iXW+HgnUkwlj1DohNVw0GsnGIh1gZ\n" + "u95ff1JiUaJIkYNIkZA+hwIPFVH5aJcSCv3SPIeDS2VUAESNKHZJBQ==\n" + "-----END PUBLIC KEY-----\n"; + +static const char pubkey3[] = "-----BEGIN PUBLIC KEY-----\n" + "MCowBQYDK2VwAyEA+q5xjF5hGyyqYZidJdz/0saEQabL3N4wIZJBxNGbgJE=\n" + "-----END PUBLIC KEY-----"; static const char *pubkeys[] = {pubkey1, pubkey2, pubkey3};
Error: test_provider.c(74): error C2099: initializer is not a constant Fix this issue by making the const char* to const char[]. This is probably of one the weird array decay corner cases I could not find another/better way around this issue. Godbolt link to try: https://godbolt.org/z/s3aPb9q8q This error only occurs when building unit tests with windows which our normal build system does not do but my out of tree cmake build script tries and fails Signed-off-by: Arne Schwabe <arne@rfc2549.org> --- tests/unit_tests/openvpn/test_provider.c | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-)