[Fb-contrib-commit] SF.net SVN: fb-contrib: [890] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/d
Brought to you by:
dbrosius
From: <dbr...@us...> - 2007-06-26 21:27:24
|
Revision: 890 http://svn.sourceforge.net/fb-contrib/?rev=890&view=rev Author: dbrosius Date: 2007-06-26 14:27:23 -0700 (Tue, 26 Jun 2007) Log Message: ----------- starting to work a little, with many false positives 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-25 22:17:43 UTC (rev 889) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-06-26 21:27:23 UTC (rev 890) @@ -36,7 +36,10 @@ private BugReporter bugReporter; private OpcodeStack stack; - private Map<Integer, Object> userValues; + /** register to alias register */ + private Map<Integer, Integer> userValues; + /** alias register to loop end */ + private Map<Integer, Integer> loops; /** * constructs a UTA detector given the reporter to report bugs on @@ -70,7 +73,7 @@ } /** - * implements the visitor to reset the stack and uservalues + * implements the visitor to reset the stack and userValues and loops * * @param obj the context object of the currently parsed code block */ @@ -78,10 +81,12 @@ public void visitCode(Code obj) { try { stack.resetForMethodEntry(this); - userValues = new HashMap<Integer, Object>(); + userValues = new HashMap<Integer, Integer>(); + loops = new HashMap<Integer, Integer>(); super.visitCode(obj); } finally { userValues = null; + loops = null; } } @@ -93,7 +98,7 @@ @Override public void sawOpcode(int seen) { int reg = -1; - Object uValue = null; + Integer uValue = null; boolean sawAlias = false; boolean sawLoad = false; @@ -101,15 +106,7 @@ if (seen == INVOKEINTERFACE) { String methodName = getNameConstantOperand(); String signature = getSigConstantOperand(); - if ("size".equals(methodName) && "()I".equals(signature)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - reg = isLocalCollection(itm); - if (reg >= 0) { - sawAlias = true; - } - } - } else if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) { + if ("get".equals(methodName) && "(I)Ljava/lang/Object;".equals(signature)) { if (stack.getStackDepth() > 1) { OpcodeStack.Item itm = stack.getStackItem(1); reg = isLocalCollection(itm); @@ -117,7 +114,7 @@ sawAlias = true; } } - } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName)) { + } else if ("keySet".equals(methodName) || "values".equals(methodName) || "iterator".equals(methodName) || "next".equals(methodName) || "hasNext".equals(methodName)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); reg = isLocalCollection(itm); @@ -130,41 +127,54 @@ OpcodeStack.Item colItem = stack.getStackItem(1); OpcodeStack.Item valueItem = stack.getStackItem(0); reg = isLocalCollection(colItem); - if ((reg >= 0) - && (valueItem.getUserValue() != null)) { - bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (reg >= 0) { + uValue = (Integer)valueItem.getUserValue(); + if (uValue != null) { + Integer loopEnd = loops.get(uValue); + if ((loopEnd != null) && (getPC() < loopEnd.intValue())) { + bugReporter.reportBug(new BugInstance(this, "UAA_USE_ADD_ALL", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } + } } } } } else if (((seen == ISTORE) || ((seen >= ISTORE_0) && (seen <= ISTORE_3))) || ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3)))) { if (stack.getStackDepth() > 0) { - uValue = stack.getStackItem(0).getUserValue(); + uValue = (Integer)stack.getStackItem(0).getUserValue(); userValues.put(Integer14.valueOf(RegisterUtils.getStoreReg(this, seen)), uValue); } } else if (((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) || ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3)))) { sawLoad = true; - } else if (seen == IF_ICMPGE) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm1 = stack.getStackItem(1); - OpcodeStack.Item itm2 = stack.getStackItem(0); - reg = itm1.getRegisterNumber(); - if ((reg >= 0) && (itm1.couldBeZero())) { - uValue = itm2.getUserValue(); - if (uValue != null) { - userValues.put(Integer14.valueOf(reg), uValue); + } else if (seen == IFEQ) { + if (stack.getStackDepth() > 0) { + if (getBranchOffset() > 0) { + int gotoPos = getBranchTarget() - 3; + byte[] code = getCode().getCode(); + if ((0x00FF & code[gotoPos]) == GOTO) { + short brOffset = (short)(0x0FF & code[gotoPos+1]); + brOffset <<= 8; + brOffset |= (0x0FF & code[gotoPos+2]); + gotoPos += brOffset; + if (brOffset < getPC()) { + OpcodeStack.Item itm = stack.getStackItem(0); + uValue = (Integer)itm.getUserValue(); + if (uValue != null) { + loops.put(uValue, Integer.valueOf(getBranchTarget())); + } + } } } } } else if (seen == CHECKCAST) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); - uValue = itm.getUserValue(); - if (uValue instanceof Integer) { + uValue = (Integer)itm.getUserValue(); + if (uValue != null) { reg = ((Integer)uValue).intValue(); sawAlias = true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |