Skip to content

Commit

Permalink
Merge pull request diffblue#5663 from tautschnig/string-abstraction
Browse files Browse the repository at this point in the history
String abstraction fixes
  • Loading branch information
tautschnig authored Mar 10, 2021
2 parents 83ebd32 + 97d85c7 commit b2c7ab0
Show file tree
Hide file tree
Showing 68 changed files with 414 additions and 305 deletions.
17 changes: 0 additions & 17 deletions regression/cbmc-from-CVS/String_Abstraction1/main.c

This file was deleted.

13 changes: 0 additions & 13 deletions regression/cbmc-from-CVS/String_Abstraction11/anon-retval.c

This file was deleted.

9 changes: 0 additions & 9 deletions regression/cbmc-from-CVS/String_Abstraction12/char-array.c

This file was deleted.

15 changes: 0 additions & 15 deletions regression/cbmc-from-CVS/String_Abstraction16/ptr-arith.c

This file was deleted.

8 changes: 0 additions & 8 deletions regression/cbmc-from-CVS/String_Abstraction17/test.desc

This file was deleted.

20 changes: 0 additions & 20 deletions regression/cbmc-from-CVS/String_Abstraction19/structs.c

This file was deleted.

12 changes: 0 additions & 12 deletions regression/cbmc-from-CVS/String_Abstraction22/main.c

This file was deleted.

19 changes: 0 additions & 19 deletions regression/cbmc-from-CVS/String_Abstraction3/main.c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CORE
test.c
--string-abstraction --show-goto-functions
strlen#return_value = \(.*\)s#strarg->length - POINTER_OFFSET\(s\);
strlen#return_value = \(.*\)s#str->length - POINTER_OFFSET\(s\)\)*;
^EXIT=0$
^SIGNAL=0$
--
Expand Down
1 change: 1 addition & 0 deletions regression/cbmc-library/string-abstraction/test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-with-incr/Malloc13/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FUTURE
CORE
main.c
--string-abstraction
^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc/Malloc13/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FUTURE
CORE
main.c
--string-abstraction
^EXIT=0$
Expand Down
17 changes: 17 additions & 0 deletions regression/cbmc/String_Abstraction1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <string.h>

int main()
{
char a[100], b[100], *p;

strcpy(a, "asd");
assert(strlen(a) == 3);

a[2] = 0;
assert(strlen(a) == 2);

p = strcpy(b, a);
assert(p == b);
assert(strlen(b) == 2);
assert(strlen(p) == 2);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <string.h>

char a [10][100];
char a[10][100];

struct S
{
Expand All @@ -11,11 +11,11 @@ struct S
int main()
{
strcpy(a[0], "asd");
assert(strlen(a[0])==3);
assert(strlen(a[0]) == 3);

strcpy(s.x, "asdasd");
assert(strlen(s.x)==6);
assert(strlen(s.x) == 6);

s.p=s.x;
assert(strlen(s.p)==6);
s.p = s.x;
assert(strlen(s.p) == 6);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
CORE
KNOWNBUG
main.c
--string-abstraction --pointer-check --bounds-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
--
Multi-dimensional arrays are not yet handled properly.
16 changes: 16 additions & 0 deletions regression/cbmc/String_Abstraction11/anon-retval.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
void *malloc(unsigned);

char *foo()
{
char *a;
a = malloc(2);
a[1] = 0;
__CPROVER_is_zero_string(a) = 1;
return a;
}

int main()
{
__CPROVER_assert(
__CPROVER_is_zero_string(foo()), "CBMC failed to track return value");
}
12 changes: 12 additions & 0 deletions regression/cbmc/String_Abstraction12/char-array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int main(int argc, char *argv[])
{
char dest[10];

__CPROVER_assert(
__CPROVER_buffer_size(dest) == 10, "CBMC failed to track char array size");
dest[9] = '\0';
__CPROVER_assert(
__CPROVER_is_zero_string(dest), "CBMC failed to track char array (2)");

return 0;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

int main() {
char * x;
char * y;
char * z;
x = (void*) 0;
int main()
{
char *x;
char *y;
char *z;
x = (void *)0;
__CPROVER_assume(__CPROVER_is_zero_string(x));
y = "bla";
z = (char*) 0;
z = (char *)0;
__CPROVER_assume(__CPROVER_is_zero_string(z));
assert(__CPROVER_is_zero_string(x));
assert(__CPROVER_is_zero_string(y));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
void * malloc(unsigned);
void *malloc(unsigned);

void use_str(char * s) {
void use_str(char *s)
{
assert(__CPROVER_is_zero_string(s));
}

int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
unsigned short len;
char * str;
char *str;
__CPROVER_assume(len > 0);
str = malloc(len);
__CPROVER_assume(__CPROVER_buffer_size(str) == len);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
void * malloc(unsigned);
void *malloc(unsigned);

void use_str(char * s) {
void use_str(char *s)
{
assert(__CPROVER_is_zero_string(s));
}

int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
unsigned short len;
char * str;
char *str;
__CPROVER_assume(len > 0);
str = malloc(len);
__CPROVER_assume(__CPROVER_buffer_size(str) == len);
Expand Down
16 changes: 16 additions & 0 deletions regression/cbmc/String_Abstraction16/ptr-arith.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <string.h>

void *malloc(__CPROVER_size_t);

int main(int argc, char *argv[])
{
char *name;

name = malloc(10);
__CPROVER_assume(__CPROVER_buffer_size(name) == 20);
name = strcpy(name, "abcdefghi");
name = strcpy(name + 5 - 1, "xxxxx");
assert(__CPROVER_is_zero_string(name));

return 0;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
void * malloc(unsigned);
void *malloc(unsigned);

char * make_str() {
char *make_str()
{
unsigned short len;
char * str;
char *str;

__CPROVER_assume(len > 0);
str = malloc(len);
Expand All @@ -14,9 +15,10 @@ char * make_str() {
return str;
}

int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
char dest[10];
char * name;
char *name;

name = make_str();
__CPROVER_assume(strlen(name) < 10);
Expand Down
11 changes: 11 additions & 0 deletions regression/cbmc/String_Abstraction17/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
strcpy-no-decl.c
--string-abstraction --validate-goto-model
Condition: strlen type inconsistency
^EXIT=(127|134)$
^SIGNAL=0$
--
^warning: ignoring
--
While this test currently passes when omitting --validate-goto-model, we should
expect a report of type inconsistencies as no forward declarations are present.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <string.h>

void * malloc(unsigned);
void *malloc(__CPROVER_size_t);

char * make_str() {
char *make_str()
{
unsigned short len;
char * str;
char *str;

__CPROVER_assume(len > 0);
str = malloc(len);
Expand All @@ -16,9 +17,10 @@ char * make_str() {
return str;
}

int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
char dest[10];
char * name;
char *name;

name = make_str();
// assert(strlen(name) < 10);
Expand Down
24 changes: 24 additions & 0 deletions regression/cbmc/String_Abstraction19/structs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
void *malloc(unsigned);

typedef struct str_struct
{
int a;
char *str;
char *str2;
} str_struct_t;

str_struct_t *foo()
{
str_struct_t retval;
retval.str = malloc(2);
__CPROVER_is_zero_string(retval.str) = 1;
return &retval;
}

int main()
{
str_struct_t *a;
a = foo();
__CPROVER_assert(
__CPROVER_is_zero_string(a->str), "CBMC failed to track struct");
}
Loading

0 comments on commit b2c7ab0

Please sign in to comment.