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
fd402799
Commit
fd402799
authored
May 02, 2018
by
soad003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Static Analysis: unassigned binops, bug fix, wording
parent
25591ed8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
9 deletions
+19
-9
assignAndCompare.js
remix-solidity/src/analysis/modules/assignAndCompare.js
+5
-6
staticAnalysisCommon.js
remix-solidity/src/analysis/modules/staticAnalysisCommon.js
+11
-2
staticAnalysisIntegration-test.js
...-solidity/test/analysis/staticAnalysisIntegration-test.js
+1
-1
blockLevelCompare.sol
...lidity/test/analysis/test-contracts/blockLevelCompare.sol
+2
-0
No files found.
remix-solidity/src/analysis/modules/assignAndCompare.js
View file @
fd402799
var
name
=
'
Assign or Compare
: '
var
desc
=
'
Assign and compare operators can be confusing
.'
var
name
=
'
Result not used
: '
var
desc
=
'
The result of an operation was not used
.'
var
categories
=
require
(
'./categories'
)
var
common
=
require
(
'./staticAnalysisCommon'
)
...
...
@@ -8,15 +8,14 @@ function assignAndCompare () {
}
assignAndCompare
.
prototype
.
visit
=
function
(
node
)
{
if
(
common
.
isBlockWithTopLevelUnAssignedBinOp
(
node
))
this
.
warningNodes
.
push
(
node
)
if
(
common
.
isBlockWithTopLevelUnAssignedBinOp
(
node
))
common
.
getUnAssignedTopLevelBinOps
(
node
).
forEach
((
n
)
=>
this
.
warningNodes
.
push
(
n
)
)
}
assignAndCompare
.
prototype
.
report
=
function
(
compilationResults
)
{
return
this
.
warningNodes
.
map
(
function
(
item
,
i
)
{
return
{
warning
:
'Use of "this" for local functions: Never use this to call functions in the same contract, it only consumes more gas than normal local calls.'
,
location
:
item
.
src
,
more
:
'http://solidity.readthedocs.io/en/develop/control-structures.html#external-function-calls'
warning
:
'A binary operation yields a value that is not used in the following. This is often caused by confusing assignment (=) and comparison (==).'
,
location
:
item
.
src
}
})
}
...
...
remix-solidity/src/analysis/modules/staticAnalysisCommon.js
View file @
fd402799
...
...
@@ -24,7 +24,8 @@ var nodeTypes = {
RETURN
:
'Return'
,
IFSTATEMENT
:
'IfStatement'
,
FORSTATEMENT
:
'ForStatement'
,
WHILESTATEMENT
:
'WhileStatement'
WHILESTATEMENT
:
'WhileStatement'
,
DOWHILESTATEMENT
:
'DoWhileStatement'
}
var
basicTypes
=
{
...
...
@@ -385,6 +386,10 @@ function getFullQuallyfiedFuncDefinitionIdent (contract, func, paramTypes) {
return
getContractName
(
contract
)
+
'.'
+
getFunctionDefinitionName
(
func
)
+
'('
+
util
.
concatWithSeperator
(
paramTypes
,
','
)
+
')'
}
function
getUnAssignedTopLevelBinOps
(
blocklike
)
{
return
blocklike
.
children
.
filter
(
isBinaryOpInExpression
)
}
// #################### Trivial Node Identification
function
isFunctionDefinition
(
node
)
{
...
...
@@ -621,7 +626,10 @@ function isBlockWithTopLevelUnAssignedBinOp (node) {
}
function
isBlockLikeStatement
(
node
)
{
return
(
nodeType
(
node
,
exactMatch
(
nodeTypes
.
IFSTATEMENT
))
||
nodeType
(
node
,
exactMatch
(
nodeTypes
.
FORSTATEMENT
))
||
nodeType
(
node
,
exactMatch
(
nodeTypes
.
WHILESTATEMENT
)))
&&
return
(
nodeType
(
node
,
exactMatch
(
nodeTypes
.
IFSTATEMENT
))
||
nodeType
(
node
,
exactMatch
(
nodeTypes
.
FORSTATEMENT
))
||
nodeType
(
node
,
exactMatch
(
nodeTypes
.
WHILESTATEMENT
))
||
nodeType
(
node
,
exactMatch
(
nodeTypes
.
DOWHILESTATEMENT
)))
&&
minNrOfChildren
(
node
,
2
)
&&
!
nodeType
(
node
.
children
[
1
],
exactMatch
(
nodeTypes
.
BLOCK
))
}
...
...
@@ -937,6 +945,7 @@ module.exports = {
getStateVariableDeclarationsFormContractNode
:
getStateVariableDeclarationsFormContractNode
,
getFunctionOrModifierDefinitionParameterPart
:
getFunctionOrModifierDefinitionParameterPart
,
getFunctionOrModifierDefinitionReturnParameterPart
:
getFunctionOrModifierDefinitionReturnParameterPart
,
getUnAssignedTopLevelBinOps
:
getUnAssignedTopLevelBinOps
,
// #################### Complex Node Identification
isDeleteOfDynamicArray
:
isDeleteOfDynamicArray
,
...
...
remix-solidity/test/analysis/staticAnalysisIntegration-test.js
View file @
fd402799
...
...
@@ -559,7 +559,7 @@ test('Integration test assignAndCompare.js', function (t) {
'forgottenReturn.sol'
:
0
,
'selfdestruct.sol'
:
0
,
'deleteDynamicArray.sol'
:
0
,
'blockLevelCompare.sol'
:
6
'blockLevelCompare.sol'
:
8
}
runModuleOnFiles
(
module
,
t
,
(
file
,
report
)
=>
{
...
...
remix-solidity/test/analysis/test-contracts/blockLevelCompare.sol
View file @
fd402799
...
...
@@ -32,11 +32,13 @@ contract grr {
while(false) {
int c = 3;
uint(c) + a;
c == 5;
}
a + b;
breaker = false;
}
...
...
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