@@ -99,6 +99,25 @@ static bool read_uint_counters(const std::string &str,
99
99
return true ;
100
100
}
101
101
102
+ // Reads the next word in str and converts it into an unsigned.
103
+ // Returns true if a valid integer was read or false if an error occurred.
104
+ // pos is updated to the position immediately following the parsed word
105
+ // even if an error occurs.
106
+ static bool read_uint32_counters (const std::string &str,
107
+ std::string::size_type &pos, uint32_t &val,
108
+ std::vector<int > &counters) noexcept {
109
+ std::string result;
110
+ pos = read_word (str, pos, result);
111
+ decrement_section_counters (counters);
112
+ try {
113
+ val = static_cast <uint32_t >(std::stoul (result));
114
+ } catch (const std::exception &e) {
115
+ UNREFERENCED_PARAMETER (e);
116
+ return false ;
117
+ }
118
+ return true ;
119
+ }
120
+
102
121
// Reads the next word in str and converts it into an unsigned.
103
122
// Returns true if a valid integer was read or false if an error occurred.
104
123
// pos is updated to the position immediately following the parsed word
@@ -501,10 +520,10 @@ bool acl_load_device_def_from_str(const std::string &config_str,
501
520
devdef.num_device_global = num_device_global;
502
521
503
522
// read total number of fields in device global
504
- int total_fields_device_global = 0 ;
523
+ unsigned int total_fields_device_global = 0 ;
505
524
if (result) {
506
- result = read_int_counters (config_str, curr_pos,
507
- total_fields_device_global, counters);
525
+ result = read_uint_counters (config_str, curr_pos,
526
+ total_fields_device_global, counters);
508
527
}
509
528
510
529
for (auto i = 0U ; result && (i < num_device_global);
@@ -525,18 +544,27 @@ bool acl_load_device_def_from_str(const std::string &config_str,
525
544
read_uint_counters (config_str, curr_pos, dev_global_addr, counters);
526
545
}
527
546
// read device global address size
528
- unsigned int dev_global_size = 0 ; // Default
547
+ uint32_t dev_global_size = 0 ; // Default
529
548
if (result && counters.back () > 0 ) {
530
- result =
531
- read_uint_counters (config_str, curr_pos, dev_global_size, counters);
549
+ result = read_uint32_counters (config_str, curr_pos, dev_global_size,
550
+ counters);
532
551
}
533
552
534
- acl_device_global_mem_def_t dev_global_def = {
535
- device_global_name, dev_global_addr, dev_global_size};
536
- devdef.device_global_mem_defs [device_global_name] = dev_global_def;
553
+ acl_device_global_mem_def_t dev_global_def = {dev_global_addr,
554
+ dev_global_size};
555
+ bool ok = devdef.device_global_mem_defs
556
+ .insert ({device_global_name, dev_global_def})
557
+ .second ;
558
+ if (!ok) {
559
+ // Device global name already exist in map, but it should have been
560
+ // unique.
561
+ err_ss << " Device global name should be unique. " << device_global_name
562
+ << " is repeated.\n " ;
563
+ result = false ;
564
+ }
537
565
538
- // forward compatibility: bypassing remaining fields at the end of global
539
- // memory
566
+ // forward compatibility: bypassing remaining fields at the end of device
567
+ // global memory
540
568
while (result && counters.size () > 0 &&
541
569
counters.back () > 0 ) { // total_fields_device_global>0
542
570
std::string tmp;
0 commit comments