Skip to content

Commit 0fb6a7c

Browse files
authored
Merge pull request #4101 from mtrberzi/int-to-str-leading-zeroes
z3str3: disallow leading zeroes in int-to-string conversion
2 parents 4d54b41 + 1a5d663 commit 0fb6a7c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/smt/theory_str.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8933,11 +8933,19 @@ namespace smt {
89338933
if (Sval_expr_exists) {
89348934
zstring Sval;
89358935
u.str.is_string(Sval_expr, Sval);
8936-
TRACE("str", tout << "string theory assigns \"" << mk_pp(a, m) << " = " << Sval << "\n";);
8936+
TRACE("str", tout << "string theory assigns " << mk_pp(a, m) << " = \"" << Sval << "\"\n";);
89378937
// empty string --> integer value < 0
89388938
if (Sval.empty()) {
89398939
// ignore this. we should already assert the axiom for what happens when the string is ""
89408940
} else {
8941+
// check for leading zeroes. if the first character is '0', the entire string must be "0"
8942+
char firstChar = (int)Sval[0];
8943+
if (firstChar == '0' && !(Sval == zstring("0"))) {
8944+
TRACE("str", tout << "str.to-int argument " << Sval << " contains leading zeroes" << std::endl;);
8945+
expr_ref axiom(m.mk_not(ctx.mk_eq_atom(a, mk_string(Sval))), m);
8946+
assert_axiom(axiom);
8947+
return true;
8948+
}
89418949
// nonempty string --> convert to correct integer value, or disallow it
89428950
rational convertedRepresentation(0);
89438951
rational ten(10);

0 commit comments

Comments
 (0)