@@ -794,12 +794,13 @@ static optionalt<exprt> get_array(
794
794
return {};
795
795
}
796
796
797
- unsigned n ;
798
- if (to_unsigned_integer ( to_constant_expr (size_val), n) )
797
+ auto n_opt = numeric_cast< unsigned >(size_val) ;
798
+ if (!n_opt )
799
799
{
800
800
stream << " (sr::get_array) size is not valid" << eom;
801
801
return {};
802
802
}
803
+ unsigned n = *n_opt;
803
804
804
805
const array_typet ret_type (char_type, from_integer (n, index_type));
805
806
array_exprt ret (ret_type);
@@ -824,9 +825,11 @@ static optionalt<exprt> get_array(
824
825
for (size_t i = 0 ; i < arr_val.operands ().size (); i += 2 )
825
826
{
826
827
exprt index = arr_val.operands ()[i];
827
- unsigned idx;
828
- if (!to_unsigned_integer (to_constant_expr (index), idx) && idx<n)
829
- initial_map[idx] = arr_val.operands ()[i + 1 ];
828
+ if (auto idx = numeric_cast<std::size_t >(index))
829
+ {
830
+ if (*idx < n)
831
+ initial_map[*idx] = arr_val.operands ()[i + 1 ];
832
+ }
830
833
}
831
834
832
835
// Pad the concretized values to the left to assign the uninitialized
@@ -855,8 +858,7 @@ static std::string string_of_array(const array_exprt &arr)
855
858
return std::string (" " );
856
859
857
860
exprt size_expr=to_array_type (arr.type ()).size ();
858
- PRECONDITION (size_expr.id ()==ID_constant);
859
- to_unsigned_integer (to_constant_expr (size_expr), n);
861
+ auto n = numeric_cast_v<unsigned >(size_expr);
860
862
return utf16_constant_array_to_java (arr, n);
861
863
}
862
864
0 commit comments