[Fb-contrib-commit] SF.net SVN: fb-contrib: [891] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/d
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-06-26 21:55:46
|
Revision: 891 http://svn.sourceforge.net/fb-contrib/?rev=891&view=rev Author: dbrosius Date: 2007-06-26 14:55:38 -0700 (Tue, 26 Jun 2007) Log Message: ----------- remove false positives when the add is in a conditional (inside the loop) Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-26 21:27:23 UTC (rev 890) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-26 21:55:38 UTC (rev 891) @@ -38,8 +38,8 @@ private OpcodeStack stack; /** register to alias register */ private Map<Integer, Integer> userValues; - /** alias register to loop end */ - private Map<Integer, Integer> loops; + /** alias register to loop info */ + private Map<Integer, LoopInfo> loops; /** * constructs a UTA detector given the reporter to report bugs on @@ -82,7 +82,7 @@ try { stack.resetForMethodEntry(this); userValues = new HashMap<Integer, Integer>(); - loops = new HashMap<Integer, Integer>(); + loops = new HashMap<Integer, LoopInfo>(); super.visitCode(obj); } finally { userValues = null; @@ -130,8 +130,8 @@ if (reg >= 0) { uValue = (Integer)valueItem.getUserValue(); if (uValue != null) { - Integer loopEnd = loops.get(uValue); - if ((loopEnd != null) && (getPC() < loopEnd.intValue())) { + LoopInfo loop = loops.get(uValue); + if ((loop != null) && loop.isInLoop(getPC())) { bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) .addClass(this) .addMethod(this) @@ -164,12 +164,24 @@ OpcodeStack.Item itm = stack.getStackItem(0); uValue = (Integer)itm.getUserValue(); if (uValue != null) { - loops.put(uValue, Integer.valueOf(getBranchTarget())); + loops.put(uValue, new LoopInfo(getPC(), getBranchTarget())); } } + } else { + LoopInfo loop = findLoop(getPC()); + if (loop != null) { + loop.addConditionalRange(getPC(), getBranchTarget()); + } } } } + } else if ((seen > IFEQ) && (seen <= IF_ACMPNE)) { + if (getBranchOffset() > 0) { + LoopInfo loop = findLoop(getPC()); + if (loop != null) { + loop.addConditionalRange(getPC(), getBranchTarget()); + } + } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); @@ -225,4 +237,45 @@ return -1; } + + private LoopInfo findLoop(int pc) { + for (LoopInfo loop : loops.values()) { + if (loop.isInLoop(pc)) + return loop; + } + + return null; + } + + static class LoopInfo + { + private int start; + private int end; + private Map<Integer, Integer> conditionalRanges = new HashMap<Integer, Integer>(); + + public LoopInfo(int loopStart, int loopEnd) + { + start = loopStart; + end = loopEnd; + } + + public void addConditionalRange(int condStart, int condEnd) + { + conditionalRanges.put(Integer14.valueOf(condStart), Integer14.valueOf(condEnd)); + } + + public boolean isInLoop(int pc) + { + if ((pc < start) || (pc > end)) + return false; + + for (Map.Entry<Integer, Integer> entry : conditionalRanges.entrySet()) + { + if ((pc >= entry.getKey().intValue()) && pc <= entry.getValue().intValue()) + return false; + } + + return true; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |