loop over dynamic array length will show warning

pull/5370/head
aniket-engg 5 years ago
parent b8696a4dfe
commit 71669f3b63
  1. 5
      remix-analyzer/src/solidity-analyzer/modules/forLoopIteratesOverDynamicArray.js
  2. 10
      remix-analyzer/src/solidity-analyzer/modules/staticAnalysisCommon.js

@ -8,9 +8,8 @@ function forLoopIteratesOverDynamicArray () {
}
forLoopIteratesOverDynamicArray.prototype.visit = function (node) {
if (common.isForLoop(node) &&
node.children[1].children[1].attributes.member_name === 'length' &&
node.children[1].children[1].children[0].attributes.type.indexOf('[]') !== -1) {
if (common.isForLoop(node) && (common.isDynamicArrayLengthAccess(node.children[1].children[1]) ||
(node.children[1].children[1].children && common.isDynamicArrayLengthAccess(node.children[1].children[1].children[0])))) {
this.relevantNodes.push(node)
}
}

@ -517,6 +517,15 @@ function isDynamicArrayAccess (node) {
return node && nodeType(node, exactMatch(nodeTypes.IDENTIFIER)) && (node.attributes.type.endsWith('[] storage ref') || node.attributes.type === 'bytes storage ref' || node.attributes.type === 'string storage ref')
}
/**
* True if node accesses 'length' member of array
* @node {ASTNode} node to check for
* @return {bool}
*/
function isDynamicArrayLengthAccess (node) {
return node && nodeType(node, exactMatch(nodeTypes.MEMBERACCESS)) && (node.attributes.member_name === 'length') && node.children[0].attributes.type.indexOf('[]') !== -1
}
/**
* True if node is a delete instruction for an element from a dynamic array
* @node {ASTNode} node to check for
@ -1111,6 +1120,7 @@ module.exports = {
isAbiNamespaceCall: isAbiNamespaceCall,
isSpecialVariableAccess: isSpecialVariableAccess,
isDynamicArrayAccess: isDynamicArrayAccess,
isDynamicArrayLengthAccess: isDynamicArrayLengthAccess,
isIndexAccess: isIndexAccess,
isMappingIndexAccess: isMappingIndexAccess,
isSubScopeWithTopLevelUnAssignedBinOp: isSubScopeWithTopLevelUnAssignedBinOp,

Loading…
Cancel
Save