-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the semantics of
strlen
on symbolic strings.
Previously, `strlen` would recurse down a string until it ran into a concrete zero. This is fine, except that it would assert that each load along the way would succeed, without taking into account the previous zero tests that had to fail. To correct this we need to emulate a path condition such that to load at position `n` each of the `n-1` previous locations must have been non-zero, and the loads are only required to succeed under that condition. This allows one, for example, to assume that some value in a string is 0 (but not specify which one). Previously, `strlen` would index off the end of the allocation of such a string and fail. Now it will succeed because the path condition required to index out-of-bounds is inconsistent. Fixes #468
- Loading branch information
1 parent
5c46b3a
commit 67ae4a9
Showing
3 changed files
with
47 additions
and
9 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
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,23 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "crucible.h" | ||
|
||
#define MAX 10 | ||
|
||
char* mkstr() { | ||
char* x = malloc(MAX); | ||
for( int i=0; i<MAX; i++ ) { | ||
x[i] = crucible_int8_t( "x" ); | ||
} | ||
|
||
assuming( x[MAX-1] == 0 ); | ||
|
||
return x; | ||
} | ||
|
||
int main() { | ||
char *str = mkstr(); | ||
size_t sz = strlen(str); | ||
check( sz < MAX ); | ||
} |
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 @@ | ||
[Crux] Overall status: Valid. |