Skip to content

Commit 882bbb1

Browse files
Fix eval of concatenation builtin functions
The previous version was not handling correcly the case where end_index was smaller than start_index.
1 parent ad9b86c commit 882bbb1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/solvers/refinement/string_refinement_util.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,19 @@ std::vector<mp_integer> string_concatenation_builtin_functiont::eval(
292292
const std::vector<mp_integer> &input2_value,
293293
const std::vector<mp_integer> &args_value) const
294294
{
295-
const std::size_t start_index =
296-
args_value.size() > 0 && args_value[0] > 0 ? args_value[0].to_ulong() : 0;
297-
const std::size_t end_index = args_value.size() > 1 && args_value[1] > 0
298-
? args_value[1].to_ulong()
299-
: input2_value.size();
295+
const auto start_index =
296+
args_value.size() > 0 && args_value[0] > 0 ? args_value[0] : mp_integer(0);
297+
const mp_integer input2_size(input2_value.size());
298+
const auto end_index =
299+
args_value.size() > 1
300+
? std::max(std::min(args_value[1], input2_size), start_index)
301+
: input2_size;
300302

301303
std::vector<mp_integer> result(input1_value);
302304
result.insert(
303305
result.end(),
304-
input2_value.begin() + start_index,
305-
input2_value.begin() + end_index);
306+
input2_value.begin() + numeric_cast_v<std::size_t>(start_index),
307+
input2_value.begin() + numeric_cast_v<std::size_t>(end_index));
306308
return result;
307309
}
308310

0 commit comments

Comments
 (0)