Skip to content

Commit 95d089d

Browse files
Setting the default of integer_of_expr to 0
This function is only used for getting some strings from the current valuation given by the string solver, so if the value is not a valid constant, we can replace it by 0 to get one possible valuation.
1 parent 2ab3e49 commit 95d089d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/solvers/refinement/string_refinement.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -282,29 +282,29 @@ void string_refinementt::add_lemma(const exprt &lemma, bool add_to_index_set)
282282
cur.push_back(lemma);
283283
}
284284

285-
int integer_of_expr(const constant_exprt & expr)
285+
unsigned integer_of_expr(const constant_exprt & expr)
286286
{
287287
mp_integer i;
288-
assert(!to_integer(expr,i));
288+
if(to_integer(expr,i))
289+
return 0;
289290
if(i<0)
290-
return -integer2unsigned(-i);
291+
return 0;
291292
else
292293
return integer2unsigned(i);
293294
}
294295

295296
std::string string_refinementt::string_of_array(const exprt &arr, const exprt &size)
296297
{
297298
if(size.id() != ID_constant) return "string of unknown size";
298-
int n = integer_of_expr(to_constant_expr(size));
299-
if(n<0) return "string of wrong size";
299+
unsigned n=integer_of_expr(to_constant_expr(size));
300300
if(n>500) return "very long string";
301301
if(n==0) return "\"\"";
302302
unsigned str[n];
303303
exprt val = get(arr);
304304
if(val.id() == "array-list") {
305305
for (size_t i = 0; i < val.operands().size()/2; i++) {
306306
exprt index = val.operands()[i*2];
307-
int idx = integer_of_expr(to_constant_expr(index));
307+
unsigned idx = integer_of_expr(to_constant_expr(index));
308308
if(idx<n)
309309
{
310310
exprt value = val.operands()[i*2+1];

0 commit comments

Comments
 (0)