From 2490170aacf4b7b462e63042a89275c142a88e16 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Wed, 14 Dec 2016 19:31:59 -0800 Subject: [PATCH] Handle empty function body edge case --- instrumentSolidity.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/instrumentSolidity.js b/instrumentSolidity.js index 506edb7..f29cf55 100644 --- a/instrumentSolidity.js +++ b/instrumentSolidity.js @@ -135,10 +135,15 @@ module.exports = function(contract, fileName, instrumentingActive){ var startcol = expression.start - contract.slice(0,expression.start).lastIndexOf('\n') -1; var endlineDelta = contract.slice(expression.start).indexOf('{')+1; var functionDefinition = contract.slice(expression.start, expression.start + endlineDelta); + var lastChar = contract.slice(expression.start, expression.start + endlineDelta + 1).slice(-1); var endline = startline + (functionDefinition.match(/\n/g)||[]).length; var endcol = functionDefinition.length - functionDefinition.lastIndexOf('\n') fnMap[fnId] = {name: expression.name, line: linecount, loc:{start:{line: startline, column:startcol},end:{line:endline, column:endcol}}} - createOrAppendInjectionPoint(expression.start + endlineDelta+1,{type: "callFunctionEvent", fnId: fnId} ); + if (lastChar === '}'){ + createOrAppendInjectionPoint(expression.start + endlineDelta,{type: "callFunctionEvent", fnId: fnId} ); + } else { + createOrAppendInjectionPoint(expression.start + endlineDelta+1,{type: "callFunctionEvent", fnId: fnId} ); + } } function instrumentIfStatement(expression){