Skip to content

Commit eaaf057

Browse files
committed
Avoid invalid shift caused by excessive object bits
Use mp_integer to compute the number of permitted objects as the number of object bits is related to the analysis target platform and need not be within the analysis-execution platform's limits.
1 parent cb88728 commit eaaf057

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/solvers/smt2_incremental/convert_expr_to_smt.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,21 +877,23 @@ static smt_termt convert_expr_to_smt(
877877
"Objects should be tracked before converting their address to SMT terms");
878878
const std::size_t object_id = object->second.unique_id;
879879
const std::size_t object_bits = config.bv_encoding.object_bits;
880-
const std::size_t max_objects = std::size_t(1) << object_bits;
880+
const mp_integer max_objects = power(2, object_bits);
881881
if(object_id >= max_objects)
882882
{
883883
throw analysis_exceptiont{
884884
"too many addressed objects: maximum number of objects is set to 2^n=" +
885-
std::to_string(max_objects) + " (with n=" + std::to_string(object_bits) +
885+
integer2string(max_objects) + " (with n=" + std::to_string(object_bits) +
886886
"); " +
887887
"use the `--object-bits n` option to increase the maximum number"};
888888
}
889889
const smt_termt object_bit_vector =
890890
smt_bit_vector_constant_termt{object_id, object_bits};
891-
INVARIANT(
892-
type->get_width() > object_bits,
893-
"Pointer should be wider than object_bits in order to allow for offset "
894-
"encoding.");
891+
if(type->get_width() <= object_bits)
892+
{
893+
throw analysis_exceptiont{
894+
"pointer should be wider than object_bits in order to allow for offset "
895+
"encoding"};
896+
}
895897
const size_t offset_bits = type->get_width() - object_bits;
896898
if(expr_try_dynamic_cast<symbol_exprt>(address_of.object()))
897899
{

0 commit comments

Comments
 (0)