@@ -311,22 +311,12 @@ TEST(eof_validation, EOF1_invalid_section_0_type)
311
311
312
312
TEST (eof_validation, EOF1_too_many_code_sections)
313
313
{
314
- std::string code_sections_1024;
315
- std::string code_sections_1025;
316
- for (int i = 0 ; i < 1025 ; ++i)
317
- if (i < 1023 )
318
- {
319
- code_sections_1024 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
320
- code_sections_1025 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
321
- }
322
- else if (i == 1023 )
323
- {
324
- code_sections_1024 += " 5B5B00" ;
325
- code_sections_1025 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
326
- }
327
- else
328
- code_sections_1025 += " 5B5B00" ;
314
+ std::string cs_calling_next;
315
+ for (int i = 0 ; i < 1023 ; ++i)
316
+ cs_calling_next += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
329
317
318
+ const std::string code_sections_1024 = cs_calling_next + " 5B5B00" ;
319
+ const std::string code_sections_1025 = cs_calling_next + " E504005B5B00" ;
330
320
331
321
const auto valid = " EF0001 011000" + bytecode{" 020400" } + 0x400 * bytecode{" 0003" } +
332
322
" 040000 00" + 0x400 * bytecode{" 00800000" } + code_sections_1024;
@@ -873,11 +863,9 @@ TEST(eof_validation, multiple_code_sections_headers)
873
863
TEST (eof_validation, many_code_sections_1023)
874
864
{
875
865
std::string code_sections_1023;
876
- for (auto i = 0 ; i < 1023 ; ++i)
877
- if (i < 1022 )
878
- code_sections_1023 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
879
- else
880
- code_sections_1023 += " 5B5B00" ;
866
+ for (auto i = 0 ; i < 1022 ; ++i)
867
+ code_sections_1023 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
868
+ code_sections_1023 += " 5B5B00" ;
881
869
882
870
const auto code = " EF0001 010FFC 0203FF " + 1023 * bytecode{" 0003" } + " 040000 00" +
883
871
1023 * bytecode{" 00800000" } + code_sections_1023;
@@ -888,11 +876,9 @@ TEST(eof_validation, many_code_sections_1023)
888
876
TEST (eof_validation, many_code_sections_1024)
889
877
{
890
878
std::string code_sections_1024;
891
- for (auto i = 0 ; i < 1024 ; ++i)
892
- if (i < 1023 )
893
- code_sections_1024 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
894
- else
895
- code_sections_1024 += " 5B5B00" ;
879
+ for (auto i = 0 ; i < 1023 ; ++i)
880
+ code_sections_1024 += " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
881
+ code_sections_1024 += " 5B5B00" ;
896
882
897
883
const auto code = " EF0001 011000 020400 " + 1024 * bytecode{" 0003" } + " 040000 00" +
898
884
1024 * bytecode{" 00800000" } + code_sections_1024;
@@ -1248,54 +1234,24 @@ TEST(eof_validation, unreachable_code_sections)
1248
1234
}
1249
1235
1250
1236
{
1251
- std::string section_size_256;
1252
- std::string section_types_256;
1253
- std::string code_sections_256_err_001;
1254
- std::string code_sections_256_err_254;
1255
- for (int i = 0 ; i < 256 ; ++i)
1237
+ auto code_sections_256_err_001 = eof_bytecode (bytecode{OP_JUMPF} + " 0001" ).code (bytecode{OP_JUMPF} + " 0001" , 0 , 0x80 , 0 );
1238
+ auto code_sections_256_err_254 = eof_bytecode (bytecode{OP_JUMPF} + " 0001" ).code (bytecode{OP_JUMPF} + " 0002" , 0 , 0x80 , 0 );
1239
+ for (int i = 2 ; i < 254 ; ++i)
1256
1240
{
1257
- section_size_256 += " 0003" ;
1258
- section_types_256 += " 00800000" ;
1259
- if (i < 255 )
1260
- if (i == 1 )
1261
- {
1262
- code_sections_256_err_001 += " E5" + hex (big_endian (static_cast <uint16_t >(i)));
1263
- code_sections_256_err_254 +=
1264
- " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
1265
- }
1266
- else if (i == 254 )
1267
- {
1268
- code_sections_256_err_001 +=
1269
- " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
1270
- code_sections_256_err_254 += " E5" + hex (big_endian (static_cast <uint16_t >(i)));
1271
- }
1272
- else
1273
- {
1274
- code_sections_256_err_001 +=
1275
- " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
1276
- code_sections_256_err_254 +=
1277
- " E5" + hex (big_endian (static_cast <uint16_t >(i + 1 )));
1278
- }
1279
- else
1280
- {
1281
- code_sections_256_err_001 += " 5B5B00" ;
1282
- code_sections_256_err_254 += " 5B5B00" ;
1283
- }
1241
+ code_sections_256_err_001.code (bytecode{OP_JUMPF} + hex (big_endian (static_cast <uint16_t >(i + 1 ))), 0 , 0x80 , 0 );
1242
+ code_sections_256_err_254.code (bytecode{OP_JUMPF} + hex (big_endian (static_cast <uint16_t >(i + 1 ))), 0 , 0x80 , 0 );;
1284
1243
}
1285
1244
1245
+ code_sections_256_err_001.code (bytecode{OP_JUMPF} + " 00FF" , 0 , 0x80 , 0 ).code (3 * bytecode{" 5B" } + OP_STOP, 0 , 0x80 , 0 );
1246
+ code_sections_256_err_254.code (bytecode{OP_JUMPF} + " 00FE" , 0 , 0x80 , 0 ).code (3 * bytecode{" 5B" } + OP_STOP, 0 , 0x80 , 0 );
1247
+
1286
1248
// Code Section 1 calls itself instead of code section 2, leaving code section 2 unreachable
1287
- EXPECT_EQ (
1288
- validate_eof (from_spaced_hex (" EF00 01 010400 020100" + section_size_256 + " 040000 00" +
1289
- section_types_256 + code_sections_256_err_001)
1290
- .value ()),
1249
+ EXPECT_EQ (validate_eof (code_sections_256_err_001),
1291
1250
EOFValidationError::unreachable_code_sections);
1292
1251
1293
1252
// Code Section 254 calls itself instead of code section 255, leaving code section 255
1294
1253
// unreachable
1295
- EXPECT_EQ (
1296
- validate_eof (from_spaced_hex (" EF00 01 010400 020100" + section_size_256 + " 040000 00" +
1297
- section_types_256 + code_sections_256_err_254)
1298
- .value ()),
1254
+ EXPECT_EQ (validate_eof (code_sections_256_err_254),
1299
1255
EOFValidationError::unreachable_code_sections);
1300
1256
}
1301
1257
}
0 commit comments