@@ -400,7 +400,7 @@ int linker_script_merget::ls_data2instructions(
400
400
{
401
401
goto_programt::instructionst initialize_instructions=gp.instructions ;
402
402
std::map<irep_idt, std::size_t > truncated_symbols;
403
- for (auto &d : data[" regions" ]. array )
403
+ for (auto &d : to_json_array ( data[" regions" ]) )
404
404
{
405
405
bool has_end=d[" has-end-symbol" ].is_true ();
406
406
@@ -446,11 +446,13 @@ int linker_script_merget::ls_data2instructions(
446
446
447
447
// Since the value of the pointer will be a random CBMC address, write a
448
448
// note about the real address in the object file
449
- auto it=std::find_if (data[" addresses" ].array .begin (),
450
- data[" addresses" ].array .end (),
451
- [&d](const jsont &add)
452
- { return add[" sym" ].value ==d[" start-symbol" ].value ; });
453
- if (it==data[" addresses" ].array .end ())
449
+ auto it = std::find_if (
450
+ to_json_array (data[" addresses" ]).begin (),
451
+ to_json_array (data[" addresses" ]).end (),
452
+ [&d](const jsont &add) {
453
+ return add[" sym" ].value == d[" start-symbol" ].value ;
454
+ });
455
+ if (it == to_json_array (data[" addresses" ]).end ())
454
456
{
455
457
error () << " Start: Could not find address corresponding to symbol '"
456
458
<< d[" start-symbol" ].value << " ' (start of section)" << eom;
@@ -481,12 +483,12 @@ int linker_script_merget::ls_data2instructions(
481
483
linker_values[d[" end-symbol" ].value ]=std::make_pair (end_sym, array_end);
482
484
483
485
auto entry = std::find_if (
484
- data[" addresses" ]. array .begin (),
485
- data[" addresses" ]. array .end (),
486
+ to_json_array ( data[" addresses" ]) .begin (),
487
+ to_json_array ( data[" addresses" ]) .end (),
486
488
[&d](const jsont &add) {
487
489
return add[" sym" ].value == d[" end-symbol" ].value ;
488
490
});
489
- if (entry == data[" addresses" ]. array .end ())
491
+ if (entry == to_json_array ( data[" addresses" ]) .end ())
490
492
{
491
493
error () << " Could not find address corresponding to symbol '"
492
494
<< d[" end-symbol" ].value << " ' (end of section)" << eom;
@@ -539,7 +541,7 @@ int linker_script_merget::ls_data2instructions(
539
541
// address. These will have been declared extern too, so we need to give them
540
542
// a value also. Here, we give them the actual value that they have in the
541
543
// object file, since we're not assigning any object to them.
542
- for (const auto &d : data[" addresses" ]. array )
544
+ for (const auto &d : to_json_array ( data[" addresses" ]) )
543
545
{
544
546
auto it=linker_values.find (irep_idt (d[" sym" ].value ));
545
547
if (it!=linker_values.end ())
@@ -591,7 +593,7 @@ int linker_script_merget::ls_data2instructions(
591
593
#else
592
594
{
593
595
goto_programt::instructionst initialize_instructions=gp.instructions;
594
- for(const auto &d : data["regions"].array )
596
+ for(const auto &d : to_json_array( data["regions"]) )
595
597
{
596
598
unsigned start=safe_string2unsigned(d["start"].value);
597
599
unsigned size=safe_string2unsigned(d["size"].value);
@@ -623,7 +625,7 @@ int linker_script_merget::ls_data2instructions(
623
625
symbol_table.add(sym);
624
626
}
625
627
626
- for(const auto &d : data["addresses"].array )
628
+ for(const auto &d : to_json_array( data["addresses"]) )
627
629
{
628
630
source_locationt loc;
629
631
loc.set_file(linker_script);
@@ -738,38 +740,51 @@ int linker_script_merget::goto_and_object_mismatch(
738
740
739
741
int linker_script_merget::linker_data_is_malformed (const jsont &data) const
740
742
{
743
+ if (!data.is_object ())
744
+ return true ;
745
+
746
+ const json_objectt &data_object = to_json_object (data);
741
747
return (
742
- !(data. is_object () && data. object . find (" regions" ) != data. object .end () &&
743
- data. object . find (" addresses" ) != data. object .end () &&
748
+ !(data_object. find (" regions" ) != data_object .end () &&
749
+ data_object. find (" addresses" ) != data_object .end () &&
744
750
data[" regions" ].is_array () && data[" addresses" ].is_array () &&
745
751
std::all_of (
746
- data[" addresses" ]. array .begin (),
747
- data[" addresses" ]. array .end (),
752
+ to_json_array ( data[" addresses" ]) .begin (),
753
+ to_json_array ( data[" addresses" ]) .end (),
748
754
[](const jsont &j) {
749
- return j.is_object () && j.object .find (" val" ) != j.object .end () &&
750
- j.object .find (" sym" ) != j.object .end () &&
751
- j[" val" ].is_number () && j[" sym" ].is_string ();
755
+ if (!j.is_object ())
756
+ return false ;
757
+
758
+ const json_objectt &address = to_json_object (j);
759
+ return address.find (" val" ) != address.end () &&
760
+ address.find (" sym" ) != address.end () &&
761
+ address[" val" ].is_number () && address[" sym" ].is_string ();
752
762
}) &&
753
763
std::all_of (
754
- data[" regions" ]. array .begin (),
755
- data[" regions" ]. array .end (),
764
+ to_json_array ( data[" regions" ]) .begin (),
765
+ to_json_array ( data[" regions" ]) .end (),
756
766
[](const jsont &j) {
757
- return j.is_object () && j.object .find (" start" ) != j.object .end () &&
758
- j.object .find (" size" ) != j.object .end () &&
759
- j.object .find (" annot" ) != j.object .end () &&
760
- j.object .find (" commt" ) != j.object .end () &&
761
- j.object .find (" start-symbol" ) != j.object .end () &&
762
- j.object .find (" has-end-symbol" ) != j.object .end () &&
763
- j.object .find (" section" ) != j.object .end () &&
764
- j[" start" ].is_number () && j[" size" ].is_number () &&
765
- j[" annot" ].is_string () && j[" start-symbol" ].is_string () &&
766
- j[" section" ].is_string () && j[" commt" ].is_string () &&
767
- ((j[" has-end-symbol" ].is_true () &&
768
- j.object .find (" end-symbol" ) != j.object .end () &&
769
- j[" end-symbol" ].is_string ()) ||
770
- (j[" has-end-symbol" ].is_false () &&
771
- j.object .find (" size-symbol" ) != j.object .end () &&
772
- j.object .find (" end-symbol" ) == j.object .end () &&
773
- j[" size-symbol" ].is_string ()));
767
+ if (!j.is_object ())
768
+ return false ;
769
+
770
+ const json_objectt ®ion = to_json_object (j);
771
+ return region.find (" start" ) != region.end () &&
772
+ region.find (" size" ) != region.end () &&
773
+ region.find (" annot" ) != region.end () &&
774
+ region.find (" commt" ) != region.end () &&
775
+ region.find (" start-symbol" ) != region.end () &&
776
+ region.find (" has-end-symbol" ) != region.end () &&
777
+ region.find (" section" ) != region.end () &&
778
+ region[" start" ].is_number () && region[" size" ].is_number () &&
779
+ region[" annot" ].is_string () &&
780
+ region[" start-symbol" ].is_string () &&
781
+ region[" section" ].is_string () && region[" commt" ].is_string () &&
782
+ ((region[" has-end-symbol" ].is_true () &&
783
+ region.find (" end-symbol" ) != region.end () &&
784
+ region[" end-symbol" ].is_string ()) ||
785
+ (region[" has-end-symbol" ].is_false () &&
786
+ region.find (" size-symbol" ) != region.end () &&
787
+ region.find (" end-symbol" ) == region.end () &&
788
+ region[" size-symbol" ].is_string ()));
774
789
})));
775
790
}
0 commit comments