Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
0c428d81
Unverified
Commit
0c428d81
authored
Oct 16, 2019
by
Aniket
Committed by
GitHub
Oct 16, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1314 from ethereum/fix/#994
loop over dynamic array length will show warning
parents
4b325a60
881f95d1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
5 deletions
+26
-5
forLoopIteratesOverDynamicArray.js
...idity-analyzer/modules/forLoopIteratesOverDynamicArray.js
+12
-5
staticAnalysisCommon.js
...zer/src/solidity-analyzer/modules/staticAnalysisCommon.js
+14
-0
No files found.
remix-analyzer/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray.js
View file @
0c428d81
var
name
=
'For loop iterates over dynamic array: '
var
name
=
'For loop iterates over dynamic array: '
var
desc
=
'The number of
\'
for
\'
loop iterations depends on dynamic array
\'
s size'
var
desc
=
'The number of
\'
for
\'
loop iterations depends on dynamic array
\'
s size'
var
categories
=
require
(
'./categories'
)
var
categories
=
require
(
'./categories'
)
var
common
=
require
(
'./staticAnalysisCommon'
)
var
{
isForLoop
,
isDynamicArrayLengthAccess
,
isBinaryOperation
}
=
require
(
'./staticAnalysisCommon'
)
function
forLoopIteratesOverDynamicArray
()
{
function
forLoopIteratesOverDynamicArray
()
{
this
.
relevantNodes
=
[]
this
.
relevantNodes
=
[]
}
}
forLoopIteratesOverDynamicArray
.
prototype
.
visit
=
function
(
node
)
{
forLoopIteratesOverDynamicArray
.
prototype
.
visit
=
function
(
node
)
{
if
(
common
.
isForLoop
(
node
)
&&
if
(
isForLoop
(
node
))
{
node
.
children
[
1
].
children
[
1
].
attributes
.
member_name
===
'length'
&&
// Access 'condition' node of 'for' loop statement
node
.
children
[
1
].
children
[
1
].
children
[
0
].
attributes
.
type
.
indexOf
(
'[]'
)
!==
-
1
)
{
let
forLoopConditionNode
=
node
.
children
[
1
]
this
.
relevantNodes
.
push
(
node
)
// Access right side of condition as its children
let
conditionChildrenNode
=
forLoopConditionNode
.
children
[
1
]
// Check if it is a binary operation. if yes, check if its children node access length of dynamic array
if
(
isBinaryOperation
(
conditionChildrenNode
)
&&
isDynamicArrayLengthAccess
(
conditionChildrenNode
.
children
[
0
]))
{
this
.
relevantNodes
.
push
(
node
)
}
else
if
(
isDynamicArrayLengthAccess
(
conditionChildrenNode
))
{
// else check if condition node itself access length of dynamic array
this
.
relevantNodes
.
push
(
node
)
}
}
}
}
}
...
...
remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js
View file @
0c428d81
...
@@ -518,6 +518,18 @@ function isDynamicArrayAccess (node) {
...
@@ -518,6 +518,18 @@ function isDynamicArrayAccess (node) {
}
}
/**
/**
* True if node accesses 'length' member of dynamic array
* @node {ASTNode} node to check for
* @return {bool}
*/
function
isDynamicArrayLengthAccess
(
node
)
{
return
node
&&
// if node exists
nodeType
(
node
,
exactMatch
(
nodeTypes
.
MEMBERACCESS
))
&&
// is memberAccess Node
(
node
.
attributes
.
member_name
===
'length'
)
&&
// accessing 'length' member
node
.
children
[
0
].
attributes
.
type
.
indexOf
(
'[]'
)
!==
-
1
// member is accessed from dynamic array, notice [] without any number
}
/**
* True if node is a delete instruction for an element from a dynamic array
* True if node is a delete instruction for an element from a dynamic array
* @node {ASTNode} node to check for
* @node {ASTNode} node to check for
* @return {bool}
* @return {bool}
...
@@ -1111,6 +1123,7 @@ module.exports = {
...
@@ -1111,6 +1123,7 @@ module.exports = {
isAbiNamespaceCall
:
isAbiNamespaceCall
,
isAbiNamespaceCall
:
isAbiNamespaceCall
,
isSpecialVariableAccess
:
isSpecialVariableAccess
,
isSpecialVariableAccess
:
isSpecialVariableAccess
,
isDynamicArrayAccess
:
isDynamicArrayAccess
,
isDynamicArrayAccess
:
isDynamicArrayAccess
,
isDynamicArrayLengthAccess
:
isDynamicArrayLengthAccess
,
isIndexAccess
:
isIndexAccess
,
isIndexAccess
:
isIndexAccess
,
isMappingIndexAccess
:
isMappingIndexAccess
,
isMappingIndexAccess
:
isMappingIndexAccess
,
isSubScopeWithTopLevelUnAssignedBinOp
:
isSubScopeWithTopLevelUnAssignedBinOp
,
isSubScopeWithTopLevelUnAssignedBinOp
:
isSubScopeWithTopLevelUnAssignedBinOp
,
...
@@ -1171,6 +1184,7 @@ module.exports = {
...
@@ -1171,6 +1184,7 @@ module.exports = {
isStatement
:
isStatement
,
isStatement
:
isStatement
,
isExpressionStatement
:
isExpressionStatement
,
isExpressionStatement
:
isExpressionStatement
,
isBlock
:
isBlock
,
isBlock
:
isBlock
,
isBinaryOperation
:
isBinaryOperation
,
// #################### Constants
// #################### Constants
nodeTypes
:
nodeTypes
,
nodeTypes
:
nodeTypes
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment