You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <assert.h>
struct St {
char a[2];
char b[2];
};
int main() {
struct St data = {{1,2},{3,4}};
data.b[-1] = 5;
assert(data.a[1] == 2);
return 0;
}
The index expression data.b[-1] is for most compilers equivalent to *(data.b - 1) == *(data.a + 1). I expected CBMC to either model this correctly, or produce a failing pointer check or array bounds check. However, neither is happening. The assertion is passing, so *(data.a + 1) is unchanged by the assignment preceding the assertion. Pointer check and bounds check do not produce an assertion, let alone a failing one.
The report by cbmc is the following:
$ cbmc neg_idx.c --pointer-check --bounds-check
CBMC version 6.4.1 (cbmc-6.4.1) 64-bit x86_64 linux
Type-checking neg_idx
Generating GOTO Program
Adding CPROVER library (x86_64)
Removal of function pointers and virtual functions
Generic Property Instrumentation
Starting Bounded Model Checking
** Results:
neg_idx.c function main
[main.assertion.1] line 11 assertion data.a[1] == 2: SUCCESS
** 0 of 1 failed (1 iterations)
VERIFICATION SUCCESSFUL
The text was updated successfully, but these errors were encountered:
CBMC version: 6.4.1
OS: Linux x86_64
Test case:
The index expression data.b[-1] is for most compilers equivalent to *(data.b - 1) == *(data.a + 1). I expected CBMC to either model this correctly, or produce a failing pointer check or array bounds check. However, neither is happening. The assertion is passing, so *(data.a + 1) is unchanged by the assignment preceding the assertion. Pointer check and bounds check do not produce an assertion, let alone a failing one.
The report by cbmc is the following:
The text was updated successfully, but these errors were encountered: