Skip to content

Commit 1ad790f

Browse files
committed
Error handling for very large size arrays and vectors
This reinstates and improves the error handling for very large arrays and vectors with the limit of 1 << 30 (from old code). This prevents exceptions in the cast which can occur for extremely large values.
1 parent 273cf8b commit 1ad790f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/solvers/flattening/boolbv_width.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,12 @@ const boolbv_widtht::entryt &boolbv_widtht::get_entry(const typet &type) const
135135
else
136136
{
137137
mp_integer total = *array_size * sub_width;
138-
entry.total_width = numeric_cast_v<std::size_t>(total);
138+
if(total>(1<<30)) // realistic limit
139+
throw analysis_exceptiont("array too large for flattening");
140+
if(total < 0)
141+
entry.total_width = 0;
142+
else
143+
entry.total_width = numeric_cast_v<std::size_t>(total);
139144
}
140145
}
141146
else if(type_id==ID_vector)
@@ -146,7 +151,12 @@ const boolbv_widtht::entryt &boolbv_widtht::get_entry(const typet &type) const
146151
const auto vector_size = numeric_cast_v<mp_integer>(vector_type.size());
147152

148153
mp_integer total = vector_size * sub_width;
149-
entry.total_width = numeric_cast_v<std::size_t>(vector_size * sub_width);
154+
if(total > (1 << 30)) // realistic limit
155+
throw analysis_exceptiont("vector too large for flattening");
156+
if(total < 0)
157+
entry.total_width = 0;
158+
else
159+
entry.total_width = numeric_cast_v<std::size_t>(vector_size * sub_width);
150160
}
151161
else if(type_id==ID_complex)
152162
{

0 commit comments

Comments
 (0)