Skip to contentSkip to conversation

Fix delcarion of pubkeys in test_provider.c in MSVC builds

PATCH In review Arne Schwabe 4 participants 6 messages Aug 24, 2022 – Aug 25, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix delcarion of pubkeys in test_provider.c in MSVC builds

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

---
 tests/unit_tests/openvpn/test_provider.c | 36 ++++++++++++------------
 1 file changed, 18 insertions(+), 18 deletions(-)
tests/unit_tests/openvpn/test_provider.c +18 -18
index 3f9a26e57..9451a6e7e 100644
@@ -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};
 
Signature · 1 line
2.32.1 (Apple Git-133)
Acked-by on v1 1/1
#1 lore raw

Typo "delcarion" in summary line

Quoted 8 lines · Arne Schwabe

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?

Quoted 1 line

This error only occurs when building unit tests with windows which our

Probably better MSVC instead of Windows. Or "MSVC on Windows".

Quoted 2 lines

normal build system does not do but my out of tree cmake build script tries and fails

Actual change is trivial so

Regards,

Signature · 1 line
  Frank Lichtenheld
#2 lore raw
In reply to Arne Schwabe

Hi,

Quoted 4 lines · Arne Schwabe

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

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#3 lore raw

Hi,

Quoted 8 lines · Gert Doering
Quoted 4 lines · Arne Schwabe

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

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: Fix declaration of pubkeys in test_provider.c in MSVC builds

In reply to Arne Schwabe

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 <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg25102.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#4 lore raw
In reply to Gert Doering
Quoted 12 lines · Gert Doering

Hi,

Quoted 3 lines · Arne Schwabe

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

Quoted 1 line

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