Skip to content

Commit 526ea61

Browse files
authored
Merge pull request #5888 from tautschnig/fix-5885
Fix off-by-one error in unbounded byte update
2 parents d1f29d4 + 26ffe88 commit 526ea61

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

regression/cbmc/byte_update15/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
#include <string.h>
3+
4+
int main(void)
5+
{
6+
int src[8], dst[8], delta;
7+
if(delta == 3 || delta == 4)
8+
{
9+
memcpy(dst, src, sizeof(int) * delta);
10+
assert(dst[1] == src[1]);
11+
}
12+
return 0;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE broken-smt-backend
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/solvers/lowering/byte_operators.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ static exprt lower_byte_update_byte_array_vector(
14291429
/// \param non_const_update_bound: Constrain updates such
14301430
/// as to at most update \p non_const_update_bound elements
14311431
/// \param initial_bytes: Number of bytes from \p value_as_byte_array to use to
1432-
/// update the the array/vector element at \p first_index
1432+
/// update the array/vector element at \p first_index
14331433
/// \param first_index: Lowest index into the target array/vector of the update
14341434
/// \param first_update_value: Combined value of partially old and updated bytes
14351435
/// to use at \p first_index
@@ -1477,14 +1477,15 @@ static exprt lower_byte_update_array_vector_unbounded(
14771477
mult_exprt{subtype_size,
14781478
minus_exprt{typecast_exprt::conditional_cast(
14791479
array_comprehension_index, first_index.type()),
1480-
first_index}}};
1480+
plus_exprt{first_index,
1481+
from_integer(1, first_index.type())}}}};
14811482
exprt update_value = lower_byte_extract(
14821483
byte_extract_exprt{
14831484
extract_opcode, value_as_byte_array, std::move(offset_expr), subtype},
14841485
ns);
14851486

14861487
// The number of target array/vector elements being replaced, not including
1487-
// a possible partial update a the end of the updated range, which is handled
1488+
// a possible partial update at the end of the updated range, which is handled
14881489
// below: (non_const_update_bound + (subtype_size - 1)) / subtype_size to
14891490
// round up to the nearest multiple of subtype_size.
14901491
div_exprt updated_elements{

0 commit comments

Comments
 (0)