-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Disallow passing a empty array type to abi functions.
#16416
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
Open
rodiazet
wants to merge
2
commits into
develop
Choose a base branch
from
zere_length_array
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+280
−73
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| contract C { | ||
| function f() view public { | ||
| C[0]; | ||
| function f() pure public { | ||
| C[1]; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 6133: (52-56): Statement has no effect. | ||
| // Warning 2018: (17-63): Function state mutability can be restricted to pure |
9 changes: 9 additions & 0 deletions
9
test/libsolidity/syntaxTests/array/interface_index_access.sol
This file contains hidden or 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,9 @@ | ||
| interface I {} | ||
|
|
||
| library L { | ||
| function f() pure public { | ||
| I[1]; | ||
| } | ||
| } | ||
| // ---- | ||
| // Warning 6133: (67-71): Statement has no effect. |
33 changes: 33 additions & 0 deletions
33
test/libsolidity/syntaxTests/array/invalid/abi_decode_zero_length_array_type.sol
This file contains hidden or 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,33 @@ | ||
| contract C { | ||
| function f0() public { | ||
| abi.decode("", (int[0])); | ||
| } | ||
|
|
||
| function f1() public { | ||
| abi.decode("", (int[0][])); | ||
| } | ||
|
|
||
| function f2() public { | ||
| abi.decode("", (int[][0])); | ||
| } | ||
|
|
||
| function f3() public { | ||
| abi.decode("", (int[][0][])); | ||
| } | ||
|
|
||
| function f4() public { | ||
| abi.decode("", (int[][][0])); | ||
| } | ||
|
|
||
| struct S { uint t; } | ||
| function f5() public { | ||
| abi.decode("", (S[][][0])); | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (68-69): Array with zero length specified. | ||
| // TypeError 1406: (136-137): Array with zero length specified. | ||
| // TypeError 1406: (208-209): Array with zero length specified. | ||
| // TypeError 1406: (278-279): Array with zero length specified. | ||
| // TypeError 1406: (352-353): Array with zero length specified. | ||
| // TypeError 1406: (447-448): Array with zero length specified. |
7 changes: 7 additions & 0 deletions
7
test/libsolidity/syntaxTests/array/invalid/abi_encode_decode_zero_length_array_type.sol
This file contains hidden or 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,7 @@ | ||
| contract C { | ||
| function f() public returns (bytes memory) { | ||
| return abi.encode(abi.decode("", (int[0]))); | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (108-109): Array with zero length specified. |
7 changes: 7 additions & 0 deletions
7
test/libsolidity/syntaxTests/array/invalid/contract_zero_index_access.sol
This file contains hidden or 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,7 @@ | ||
| contract C { | ||
| function f() view public { | ||
| C[0]; | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (54-55): Array with zero length specified. |
9 changes: 9 additions & 0 deletions
9
test/libsolidity/syntaxTests/array/invalid/interface_zero_index_access.sol
This file contains hidden or 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,9 @@ | ||
| interface I {} | ||
|
|
||
| contract C { | ||
| function f() view public { | ||
| I[0]; | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (70-71): Array with zero length specified. |
4 changes: 2 additions & 2 deletions
4
test/libsolidity/syntaxTests/array/invalid/library_index_access.sol
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| library C { | ||
| library L { | ||
| function f() view public { | ||
| C[0]; | ||
| L[1]; | ||
| } | ||
| } | ||
| // ---- | ||
|
|
||
8 changes: 8 additions & 0 deletions
8
test/libsolidity/syntaxTests/array/invalid/library_zero_index_access.sol
This file contains hidden or 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,8 @@ | ||
| library L { | ||
| function f() view public { | ||
| L[0]; | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 2876: (51-55): Index access for library types and arrays of libraries are not possible. | ||
| // TypeError 1406: (53-54): Array with zero length specified. |
10 changes: 10 additions & 0 deletions
10
test/libsolidity/syntaxTests/array/invalid/super_index_access.sol
This file contains hidden or 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,10 @@ | ||
| contract B { | ||
| } | ||
|
|
||
| contract C is B { | ||
| function f(bool[] calldata dd) pure public { | ||
| super[1]; | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 5530: (91-99): Index notation is not allowed for type. |
62 changes: 50 additions & 12 deletions
62
test/libsolidity/syntaxTests/array/length/fixed_size_zero_length.sol
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,53 @@ | ||
| struct S { uint[0] x; } | ||
|
|
||
| error Err(uint[0]); | ||
| event Ev(uint[0]); | ||
|
|
||
| contract C { | ||
| int[0] a; | ||
| uint[0] b; | ||
| bytes1[0] c; | ||
| bytes32[0] d; | ||
| bytes[0] e; | ||
| string[0] f; | ||
| int[0] a; | ||
| uint[0] b; | ||
| bytes1[0] c; | ||
| bytes32[0] d; | ||
| bytes[0] e; | ||
| string[0] f; | ||
| mapping(int => int[0]) m; | ||
| function() returns (uint[0] memory) fPtr; | ||
|
|
||
| function foo () private pure { | ||
| uint[0] storage x; | ||
| } | ||
|
|
||
| function foo (uint[0] memory fArg) private pure returns(uint[0] memory) { | ||
| fArg; | ||
| } | ||
|
|
||
| function tup() private pure { | ||
| (uint[0] memory aTup, uint bTup) = ([], 1); | ||
| } | ||
|
|
||
| function cat() private pure { | ||
| try this.g() returns (uint[0] memory) {} catch (bytes memory bCatch) {} | ||
| } | ||
|
|
||
| function array_alloc() private pure { | ||
| new uint[0][](3); | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (19-20): Array with zero length specified. | ||
| // TypeError 1406: (32-33): Array with zero length specified. | ||
| // TypeError 1406: (47-48): Array with zero length specified. | ||
| // TypeError 1406: (63-64): Array with zero length specified. | ||
| // TypeError 1406: (77-78): Array with zero length specified. | ||
| // TypeError 1406: (92-93): Array with zero length specified. | ||
| // TypeError 1406: (16-17): Array with zero length specified. | ||
| // TypeError 1406: (40-41): Array with zero length specified. | ||
| // TypeError 1406: (59-60): Array with zero length specified. | ||
| // TypeError 1406: (86-87): Array with zero length specified. | ||
| // TypeError 1406: (101-102): Array with zero length specified. | ||
| // TypeError 1406: (118-119): Array with zero length specified. | ||
| // TypeError 1406: (136-137): Array with zero length specified. | ||
| // TypeError 1406: (152-153): Array with zero length specified. | ||
| // TypeError 1406: (169-170): Array with zero length specified. | ||
| // TypeError 1406: (198-199): Array with zero length specified. | ||
| // TypeError 1406: (234-235): Array with zero length specified. | ||
| // TypeError 1406: (300-301): Array with zero length specified. | ||
| // TypeError 1406: (344-345): Array with zero length specified. | ||
| // TypeError 1406: (386-387): Array with zero length specified. | ||
| // TypeError 1406: (469-470): Array with zero length specified. | ||
| // TypeError 1406: (583-584): Array with zero length specified. | ||
| // TypeError 1406: (694-695): Array with zero length specified. |
10 changes: 10 additions & 0 deletions
10
test/libsolidity/syntaxTests/array/length/fixed_size_zero_length_in_conditional.sol
This file contains hidden or 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,10 @@ | ||
| contract C { | ||
| function conditional() private pure { | ||
| true ? uint[0] : uint[0]; | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (75-76): Array with zero length specified. | ||
| // TypeError 1406: (85-86): Array with zero length specified. | ||
| // TypeError 9717: (70-77): Invalid mobile type in true expression. | ||
| // TypeError 3703: (80-87): Invalid mobile type in false expression. |
8 changes: 8 additions & 0 deletions
8
test/libsolidity/syntaxTests/array/length/fixed_size_zero_length_in_type.sol
This file contains hidden or 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,8 @@ | ||
| contract C { | ||
| function others() private pure { | ||
| type(uint[0]); | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 1406: (68-69): Array with zero length specified. | ||
| // TypeError 4259: (63-70): Invalid type for argument in the function call. An enum type, contract type or an integer type is required, but type(uint256[0] memory) provided. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.