Skip to content

Commit 22b221a

Browse files
authored
Merge pull request #9099 from gojimmypi/pr-cert-test-sizeof
Change certs_test sizeof const to define for Watcom
2 parents 8d24a30 + f279f9c commit 22b221a

2 files changed

Lines changed: 114 additions & 86 deletions

File tree

gencertbuf.pl

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@
160160
print OUT_FILE "{\n";
161161
file_to_hex($fname);
162162
print OUT_FILE "};\n";
163-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
163+
164+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
165+
# compile-time constant expression when used in a static initializer.
166+
# So don't use `static const int sizeof_` here:
167+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
164168
}
165169
print OUT_FILE "#endif /* USE_CERT_BUFFERS_1024 */\n\n";
166170

@@ -177,7 +181,10 @@
177181
print OUT_FILE "{\n";
178182
file_to_hex($fname);
179183
print OUT_FILE "};\n";
180-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
184+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
185+
# compile-time constant expression when used in a static initializer.
186+
# So don't use `static const int sizeof_` here:
187+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
181188
}
182189

183190

@@ -196,7 +203,10 @@
196203
print OUT_FILE "{\n";
197204
file_to_hex($fname);
198205
print OUT_FILE "};\n";
199-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
206+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
207+
# compile-time constant expression when used in a static initializer.
208+
# So don't use `static const int sizeof_` here:
209+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
200210
}
201211

202212
print OUT_FILE "#endif /* USE_CERT_BUFFERS_3072 */\n\n";
@@ -214,7 +224,10 @@
214224
print OUT_FILE "{\n";
215225
file_to_hex($fname);
216226
print OUT_FILE "};\n";
217-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
227+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
228+
# compile-time constant expression when used in a static initializer.
229+
# So don't use `static const int sizeof_` here:
230+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
218231
}
219232

220233
print OUT_FILE "#endif /* USE_CERT_BUFFERS_4096 */\n\n";
@@ -231,7 +244,10 @@
231244
print OUT_FILE "{\n";
232245
file_to_hex($fname);
233246
print OUT_FILE "};\n";
234-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
247+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
248+
# compile-time constant expression when used in a static initializer.
249+
# So don't use `static const int sizeof_` here:
250+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
235251
}
236252

237253
print OUT_FILE "#endif /* HAVE_FALCON */\n\n";
@@ -500,7 +516,7 @@
500516
0x12, 0xea, 0xc1, 0x94, 0x37, 0xa0, 0x11, 0xff, 0xb2, 0xa4,
501517
0xc3, 0x61, 0xf2, 0xa3, 0x49, 0xbe, 0xe7, 0xb6, 0x96, 0x2f,
502518
};
503-
static const int sizeof_bench_dilithium_level2_key = sizeof(bench_dilithium_level2_key);
519+
#define sizeof_bench_dilithium_level2_key (sizeof(bench_dilithium_level2_key))
504520
505521
#endif /* !WOLFSSL_DILITHIUM_NO_SIGN */
506522
@@ -642,8 +658,8 @@
642658
0x36, 0x8b, 0x81, 0x26, 0x99, 0x92, 0x42, 0xda, 0x45, 0xb1,
643659
0xfe, 0x4b,
644660
};
645-
static const int sizeof_bench_dilithium_level2_pubkey =
646-
sizeof(bench_dilithium_level2_pubkey);
661+
#define sizeof_bench_dilithium_level2_pubkey \\
662+
(sizeof(bench_dilithium_level2_pubkey))
647663
648664
#endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
649665
@@ -1057,7 +1073,7 @@
10571073
0xd2, 0x71, 0xb2, 0x5e, 0xae, 0x72, 0xc9, 0x69, 0x3b, 0x80,
10581074
0xc2, 0x27,
10591075
};
1060-
static const int sizeof_bench_dilithium_level3_key = sizeof(bench_dilithium_level3_key);
1076+
#define sizeof_bench_dilithium_level3_key (sizeof(bench_dilithium_level3_key))
10611077
10621078
#endif /* !WOLFSSL_DILITHIUM_NO_SIGN */
10631079
@@ -1764,7 +1780,7 @@
17641780
0x15, 0xed, 0xa6, 0x86, 0x8f, 0x2f, 0xe5, 0x67, 0x0f, 0xdd,
17651781
0xbf, 0x70, 0x53, 0xaa, 0x9b, 0x74,
17661782
};
1767-
static const int sizeof_bench_dilithium_level5_key = sizeof(bench_dilithium_level5_key);
1783+
#define sizeof_bench_dilithium_level5_key (sizeof(bench_dilithium_level5_key))
17681784
17691785
#endif /* !WOLFSSL_DILITHIUM_NO_SIGN */
17701786
@@ -2034,8 +2050,8 @@
20342050
0xe9, 0x0e, 0x42, 0xdd, 0x17, 0xd7, 0x6e, 0x19, 0x8d, 0x95,
20352051
0x0a, 0x93,
20362052
};
2037-
static const int sizeof_bench_dilithium_level5_pubkey =
2038-
sizeof(bench_dilithium_level5_pubkey);
2053+
#define sizeof_bench_dilithium_level5_pubkey \\
2054+
(sizeof(bench_dilithium_level5_pubkey))
20392055
20402056
#endif /* !WOLFSSL_DILITHIUM_NO_VERIFY */
20412057
@@ -2055,7 +2071,10 @@
20552071
print OUT_FILE "{\n";
20562072
file_to_hex($fname);
20572073
print OUT_FILE "};\n";
2058-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
2074+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
2075+
# compile-time constant expression when used in a static initializer.
2076+
# So don't use `static const int sizeof_` here:
2077+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
20592078
}
20602079

20612080
print OUT_FILE "#endif /* HAVE_SPHINCS */\n\n";
@@ -2072,7 +2091,10 @@
20722091
print OUT_FILE "{\n";
20732092
file_to_hex($fname);
20742093
print OUT_FILE "};\n";
2075-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
2094+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
2095+
# compile-time constant expression when used in a static initializer.
2096+
# So don't use `static const int sizeof_` here:
2097+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
20762098
}
20772099
print OUT_FILE "#endif /* HAVE_ECC && USE_CERT_BUFFERS_256 */\n\n";
20782100

@@ -2147,7 +2169,10 @@
21472169
print OUT_FILE "{\n";
21482170
file_to_hex($fname);
21492171
print OUT_FILE "};\n";
2150-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
2172+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
2173+
# compile-time constant expression when used in a static initializer.
2174+
# So don't use `static const int sizeof_` here:
2175+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
21512176
}
21522177
print OUT_FILE "#endif /* HAVE_ED25519 */\n\n";
21532178

@@ -2164,7 +2189,10 @@
21642189
print OUT_FILE "{\n";
21652190
file_to_hex($fname);
21662191
print OUT_FILE "};\n";
2167-
print OUT_FILE "static const int sizeof_$sname = sizeof($sname);\n\n";
2192+
# In C89/C90 (which Watcom generally defaults to), sizeof must be a
2193+
# compile-time constant expression when used in a static initializer.
2194+
# So don't use `static const int sizeof_` here:
2195+
print OUT_FILE "#define sizeof_$sname (sizeof($sname))\n\n"
21682196
}
21692197
print OUT_FILE "#endif /* USE_CERT_BUFFERS_25519 */\n\n";
21702198

0 commit comments

Comments
 (0)