Static Analysis: Bugfix constant function check, Similar var names allow number prefix, add delete dynamic array modul
parent
19275236c3
commit
fd1c024de6
@ -0,0 +1,29 @@ |
||||
var name = 'Delete on dynamic Array: ' |
||||
var desc = 'Use require and appropriately' |
||||
var categories = require('./categories') |
||||
var common = require('./staticAnalysisCommon') |
||||
|
||||
function deleteDynamicArrays () { |
||||
this.rel = [] |
||||
} |
||||
|
||||
deleteDynamicArrays.prototype.visit = function (node) { |
||||
if (common.isDeleteOfDynamicArray(node)) this.rel.push(node) |
||||
} |
||||
|
||||
deleteDynamicArrays.prototype.report = function (compilationResults) { |
||||
return this.rel.map((node) => { |
||||
return { |
||||
warning: 'The “delete” operation when applied to a dynamically sized array in Solidity generates code to delete each of the elements contained. If the array is large, this operation can surpass the block gas limit and raise an OOG exception. Also nested dynamically sized objects can produce the same results.', |
||||
location: node.src, |
||||
more: 'http://solidity.readthedocs.io/en/latest/types.html?highlight=array#delete' |
||||
} |
||||
}) |
||||
} |
||||
|
||||
module.exports = { |
||||
name: name, |
||||
description: desc, |
||||
category: categories.GAS, |
||||
Module: deleteDynamicArrays |
||||
} |
@ -0,0 +1,37 @@ |
||||
pragma solidity ^0.4.22; |
||||
contract arr { |
||||
uint[] users; |
||||
|
||||
bytes access_rights_per_user; |
||||
|
||||
uint user_index; |
||||
|
||||
address owner; |
||||
|
||||
string grr = "message"; |
||||
|
||||
uint[100] last_100_users; |
||||
|
||||
constructor(address owner1) public { |
||||
owner = owner1; |
||||
user_index = 0; |
||||
} |
||||
|
||||
function addUser(uint id, byte rights) public{ |
||||
users[user_index] = id; |
||||
last_100_users[user_index % 100] = id; |
||||
access_rights_per_user[user_index] = rights; |
||||
user_index++; |
||||
} |
||||
|
||||
function resetState() public{ |
||||
require(msg.sender == owner, grr); |
||||
delete users; |
||||
delete access_rights_per_user; |
||||
delete last_100_users; |
||||
} |
||||
|
||||
function bla(string bal) public { |
||||
grr = bal; |
||||
} |
||||
} |
Loading…
Reference in new issue