]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
JSON_ENC: Fix unit test for MSVC
authorHugo Landau <hlandau@openssl.org>
Thu, 8 Feb 2024 09:41:23 +0000 (09:41 +0000)
committerHugo Landau <hlandau@openssl.org>
Fri, 9 Feb 2024 11:03:52 +0000 (11:03 +0000)
Previously scripts were defined like this:

    {
        static const char *const script_name = "xxx";

        static const struct script_info script_info = {
            script_name, ...
        };

        return &script_info;
    }

MSVC cannot handle this, presumably because this technically involves a
load from a variable to determine that script_name equals "xxx" and it
is unable to do this during evaluation of a constant initializer list.
Resolve this by changing script_name and script_title to be arrays
instead, allowing the correct pointer values to be filled into
script_info as symbol addresses/relocations rather than dereferences.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23517)

test/json_test.c

index d2c50597190513ab2dde386e38052465ecd805e4..8cde1be2e3e5c5da4358e28e24e48f8dae1d09ca 100644 (file)
@@ -128,8 +128,8 @@ typedef void (*fp_pz_type)(OSSL_JSON_ENC *, const void *, size_t);
 #define BEGIN_SCRIPT(name, title, flags)                                       \
     static const struct script_info *get_script_##name(void)                   \
     {                                                                          \
-        const char *const script_name = #name;                                 \
-        const char *const script_title = #title;                               \
+        static const char script_name[] = #name;                               \
+        static const char script_title[] = #title;                             \
                                                                                \
         static const struct script_word script_words[] = {                     \
             OP_INIT_FLAGS(flags)