[Fb-contrib-commit] SF.net SVN: fb-contrib: [1005] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-03-15 06:17:16
|
Revision: 1005 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1005&view=rev Author: dbrosius Date: 2008-03-14 23:17:22 -0700 (Fri, 14 Mar 2008) Log Message: ----------- fix for [ 1914317 ] FalsePositive UAA_USE_ADD_ALL, postpose the reporting of UAA until you finish the loop that it occurs in, this way you can check for duplicate adds, conditional adds in ADDITION to the candidate. Modified Paths: -------------- trunk/fb-contrib/samples/UAA_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/samples/UAA_Sample.java =================================================================== --- trunk/fb-contrib/samples/UAA_Sample.java 2008-03-15 04:59:43 UTC (rev 1004) +++ trunk/fb-contrib/samples/UAA_Sample.java 2008-03-15 06:17:22 UTC (rev 1005) @@ -80,7 +80,7 @@ } } - public void testAddWithCheck(List<String> src, List<String> dst) + public void testFPAddWithCheck(List<String> src, List<String> dst) { for (String s : src) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2008-03-15 04:59:43 UTC (rev 1004) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2008-03-15 06:17:22 UTC (rev 1005) @@ -19,6 +19,7 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.apache.bcel.Repository; @@ -124,6 +125,22 @@ boolean sawLoad = false; try { + int pc = getPC(); + Iterator<LoopInfo> it = loops.values().iterator(); + while (it.hasNext()) { + LoopInfo loop = it.next(); + if ((loop.getEndPC()-3) <= pc) { + int loopPC = loop.getAddPC(); + if (loopPC > 0) { + bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this, loopPC)); + } + it.remove(); + } + } + if (seen == INVOKEINTERFACE) { String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); @@ -167,12 +184,13 @@ uValue = (Comparable<?>)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); - if ((loop != null) && loop.isInLoop(getPC(), false)) { - if (this.getCodeByte(getNextPC()) == POP) { - bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (loop != null) { + if (loop.inConditionalRange(pc)) + loop.foundAdd(-1); + else if (loop.isInLoop(pc, false)) { + if (this.getCodeByte(getNextPC()) == POP) { + loop.foundAdd(pc); + } } } } @@ -183,11 +201,13 @@ uValue = (Comparable<?>)valueItem.getUserValue(); if (uValue != null) { LoopInfo loop = loops.get(uValue); - if ((loop != null) && loop.isInLoop(getPC(), false)) { - bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (loop != null) { + if (loop.inConditionalRange(pc)) + loop.foundAdd(-1); + else if (loop.isInLoop(pc, false)) + if (this.getCodeByte(getNextPC()) == POP) { + loop.foundAdd(pc); + } } } } @@ -214,11 +234,11 @@ brOffset <<= 8; brOffset |= (0x0FF & code[gotoPos+2]); gotoPos += brOffset; - if (gotoPos < getPC()) { + if (gotoPos < pc) { OpcodeStack.Item itm = stack.getStackItem(0); uValue = (Comparable<?>)itm.getUserValue(); if (uValue != null) { - loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); + loops.put(uValue, new LoopInfo(pc, getBranchTarget())); } loopFound = true; } @@ -226,9 +246,9 @@ if (!loopFound) { - LoopInfo loop = findLoop(getPC(), true); + LoopInfo loop = findLoop(pc, true); if (loop != null) { - loop.addConditionalRange(getPC(), getBranchTarget()); + loop.addConditionalRange(pc, getBranchTarget()); } } } @@ -249,9 +269,9 @@ } } } else if (((seen > IFEQ) && (seen <= GOTO)) || (seen == IFNULL) || (seen == IFNONNULL)) { - LoopInfo loop = findLoop(getPC(), true); + LoopInfo loop = findLoop(pc, true); if (loop != null) { - loop.addConditionalRange(getPC(), getBranchOffset() > 0 ? getBranchTarget() : loop.end); + loop.addConditionalRange(pc, getBranchOffset() > 0 ? getBranchTarget() : loop.end); } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { @@ -352,12 +372,14 @@ { private int start; private int end; + private int addPC; private Map<Integer, Integer> conditionalRanges = new HashMap<Integer, Integer>(); public LoopInfo(int loopStart, int loopEnd) { start = loopStart; end = loopEnd; + addPC = 0; } public void addConditionalRange(int condStart, int condEnd) @@ -365,6 +387,16 @@ conditionalRanges.put(Integer14.valueOf(condStart), Integer14.valueOf(condEnd)); } + public boolean inConditionalRange(int pc) { + for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) + { + if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) + return true; + } + + return false; + } + public boolean isInLoop(int pc, boolean ignoreConditionals) { if ((pc < start) || (pc > end)) @@ -373,13 +405,26 @@ if (ignoreConditionals) return true; - for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) - { - if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) - return false; - } - - return true; + return !inConditionalRange(pc); } + + public void foundAdd(int pc) { + if (addPC == 0) + addPC = pc; + else + addPC = -1; + } + + public int getStartPC() { + return start; + } + + public int getEndPC() { + return end; + } + + public int getAddPC() { + return addPC; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |