@@ -309,13 +309,16 @@ exprt string_constraint_generatort::add_axioms_for_index_of(
309
309
// / \todo Change argument names to match add_axioms_for_last_index_of_string
310
310
// /
311
311
// / These axioms are :
312
- // / 1. \f$ -1 \le {\tt index} \le {\tt from\_index} \f$
312
+ // / 1. \f$ -1 \le {\tt index} \le {\tt from\_index}
313
+ // / \land {\tt index} < |{\tt haystack}| \f$
313
314
// / 2. \f$ {\tt index} = -1 \Leftrightarrow \lnot contains\f$
314
- // / 3. \f$ contains \Rightarrow ({\tt index} \le {\tt from\_index} \land
315
- // / {\tt haystack}[i] = {\tt needle} )\f$
316
- // / 4. \f$ \forall n \in [{\tt index} +1, {\tt from\_index}+1)
315
+ // / 3. \f$ contains \Rightarrow
316
+ // / {\tt haystack}[{\tt index}] = {\tt needle} )\f$
317
+ // / 4. \f$ \forall n \in [{\tt index} +1,
318
+ // / min({\tt from\_index}+1, |{\tt haystack}|))
317
319
// / .\ contains \Rightarrow {\tt haystack}[n] \ne {\tt needle} \f$
318
- // / 5. \f$ \forall m \in [0, {\tt from\_index}+1)
320
+ // / 5. \f$ \forall m \in [0,
321
+ // / min({\tt from\_index}+1, |{\tt haystack}|))
319
322
// / .\ \lnot contains \Rightarrow {\tt haystack}[m] \ne {\tt needle}\f$
320
323
// / \param str: an array of characters expression
321
324
// / \param c: a character expression
@@ -331,12 +334,11 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of(
331
334
symbol_exprt index =fresh_exist_index (" last_index_of" , index_type);
332
335
symbol_exprt contains=fresh_boolean (" contains_in_last_index_of" );
333
336
334
- exprt index1=from_integer (1 , index_type);
335
337
exprt minus1=from_integer (-1 , index_type);
336
- exprt from_index_plus_one=plus_exprt_with_overflow_check (from_index, index1);
337
338
and_exprt a1 (
338
339
binary_relation_exprt (index , ID_ge, minus1),
339
- binary_relation_exprt (index , ID_lt, from_index_plus_one));
340
+ binary_relation_exprt (index , ID_lt, from_index_plus_one),
341
+ binary_relation_exprt (index , ID_lt, str.length ()));
340
342
axioms.push_back (a1);
341
343
342
344
equal_exprt a2 (not_exprt (contains), equal_exprt (index , minus1));
@@ -351,19 +353,23 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of(
351
353
352
354
symbol_exprt n=fresh_univ_index (" QA_last_index_of1" , index_type);
353
355
string_constraintt a4 (
356
+ const exprt index1 = from_integer (1 , index_type);
357
+ const plus_exprt from_index_plus_one (from_index, index1);
358
+ const if_exprt end_index (
359
+ binary_relation_exprt (from_index_plus_one, ID_le, str.length ()),
360
+ from_index_plus_one,
361
+ str.length ());
362
+
354
363
n,
355
364
plus_exprt (index , index1),
356
- from_index_plus_one ,
365
+ end_index ,
357
366
contains,
358
367
not_exprt (equal_exprt (str[n], c)));
359
368
axioms.push_back (a4);
360
369
361
370
symbol_exprt m=fresh_univ_index (" QA_last_index_of2" , index_type);
362
371
string_constraintt a5 (
363
- m,
364
- from_index_plus_one,
365
- not_exprt (contains),
366
- not_exprt (equal_exprt (str[m], c)));
372
+ m, end_index, not_exprt (contains), notequal_exprt (str[m], c));
367
373
axioms.push_back (a5);
368
374
369
375
return index ;
0 commit comments