forked from diffblue/cbmc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Byte offset to array index translation must use array type
When dereferencing a void* pointer, the dereferenced type would always be considered compatible with the underlying object type. Nevertheless they are not actually the same. If the object was an array and the byte offset non-zero, the use of void* would yield the wrong index. The correct way to compute the index is using the actual (array) object type. Fixes: diffblue#1857
- Loading branch information
1 parent
f4fb099
commit 9df769a
Showing
3 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
int main() | ||
{ | ||
int A[3] = {1, 2, 3}; | ||
int *p = A; | ||
int v1, v2; | ||
|
||
memcpy(&v1, p, sizeof(int)); | ||
++p; | ||
memcpy(&v2, p, sizeof(int)); | ||
|
||
assert(v1 == 1); | ||
assert(v2 == 2); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters