Skip to content
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

[TG-7618] Fix precision parsing in string_format #4649

Closed
Show file tree
Hide file tree
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
Binary file modified jbmc/regression/jbmc-strings/StringFormat/Test.class
Binary file not shown.
10 changes: 10 additions & 0 deletions jbmc/regression/jbmc-strings/StringFormat/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public static String string3(String s, String t) {
assert(s.length() != 1 || u.charAt(0) == u.charAt(u.length() - 1));
return u;
}

public static String float1(float f) {
String u = String.format("Pi is %.2f.", 3.14);
// We are not checking the exactness of the string produced, just that
// the solver will not crash.
assert(u.length() > 0);
assert(u.charAt(0) == 'P');
return u;
}

}
6 changes: 6 additions & 0 deletions jbmc/regression/jbmc-strings/StringFormat/test-float1.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
Test.class
--function Test.float1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar`
^EXIT=0$
^SIGNAL=0$

Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static format_specifiert format_specifier_of_match(std::smatch &m)
int index = m[1].str().empty() ? -1 : std::stoi(m[1].str());
std::string flag = m[2].str();
int width = m[3].str().empty() ? -1 : std::stoi(m[3].str());
int precision = m[4].str().empty() ? -1 : std::stoi(m[4].str());
int precision = m[4].str().empty() ? -1 : std::stoi(m[4].str().substr(1));
std::string tT = m[5].str();

bool dt = !tT.empty();
Expand Down