Skip to content

Add a model for String.hashCode #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/java/java/lang/String.java
Original file line number Diff line number Diff line change
Expand Up @@ -2087,13 +2087,10 @@ public boolean endsWith(String suffix) {
*
* @return a hash code value for this object.
*
* @diffblue.limitedSupport
* We guarantee that two strings with different hash code have different
* content, but the exact value will not correspond to the actual one.
* @diffblue.fullSupport length of the string is limited by unwind value
*/
public int hashCode() {
// DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
return CProver.nondetInt();
// DIFFBLUE MODEL LIBRARY
// int h = hash;
// if (h == 0 && value.length > 0) {
// char val[] = value;
Expand All @@ -2104,6 +2101,12 @@ public int hashCode() {
// hash = h;
// }
// return h;
int len = length();
int h = 0;
for (int i = 0; i < len; i++) {
h = 31 * h + CProverString.charAt(this, i);
}
return h;
}

/**
Expand Down