mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker] Keep knowledge about string literals
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
bytes20 x;
|
||||
function f(bytes16 b) public view {
|
||||
b[uint8(x[2])];
|
||||
function f(uint i) public pure {
|
||||
bytes memory x = hex"00112233";
|
||||
assert(x[0] == 0x00);
|
||||
assert(x[1] == 0x11);
|
||||
require(i > 3);
|
||||
assert(x[i] == 0x00);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (161-181): Assertion violation happens here.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
pragma experimental SMTChecker;
|
||||
contract C {
|
||||
bytes20 x;
|
||||
function f(bytes16 b) public view {
|
||||
b[uint8(x[2])];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@@ -0,0 +1,15 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(uint i) public pure {
|
||||
string memory x = "\x12\x34";
|
||||
bytes memory y = bytes(x);
|
||||
assert(y[0] == 0x12);
|
||||
assert(y[1] == 0x34);
|
||||
require(i > 2);
|
||||
assert(y[i] == 0x00);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (164-184): Assertion violation happens here.
|
||||
// Warning 6328: (194-214): Assertion violation happens here.
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes memory x = hex"0123";
|
||||
assert(x.length == 2);
|
||||
}
|
||||
function g() public pure {
|
||||
bytes memory x = bytes(hex"0123");
|
||||
assert(x.length == 2);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (106-127): Assertion violation happens here.
|
||||
@@ -0,0 +1,21 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() public pure {
|
||||
string memory x = "Hello World";
|
||||
assert(bytes(x).length == 11);
|
||||
}
|
||||
function g() public pure {
|
||||
string memory x = unicode"Hello World";
|
||||
assert(bytes(x).length == 11);
|
||||
}
|
||||
function h() public pure {
|
||||
bytes memory x = unicode"Hello World";
|
||||
string memory y = string(x);
|
||||
assert(bytes(y).length == 11);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (111-140): Assertion violation happens here.
|
||||
// Warning 6328: (217-246): Assertion violation happens here.
|
||||
// Warning 6328: (353-382): Assertion violation happens here.
|
||||
Reference in New Issue
Block a user