[Fb-contrib-commit] SF.net SVN: fb-contrib:[1381] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-11-12 03:35:26
|
Revision: 1381
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1381&view=rev
Author: dbrosius
Date: 2009-11-12 03:35:19 +0000 (Thu, 12 Nov 2009)
Log Message:
-----------
latest updates for CVAA from bhaskar
Modified Paths:
--------------
trunk/fb-contrib/samples/CVAA_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java
Modified: trunk/fb-contrib/samples/CVAA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/CVAA_Sample.java 2009-10-18 15:33:09 UTC (rev 1380)
+++ trunk/fb-contrib/samples/CVAA_Sample.java 2009-11-12 03:35:19 UTC (rev 1381)
@@ -2,25 +2,26 @@
public class CVAA_Sample
{
Base[] b2;
- Derived[] d2;
class Base {}
class Derived extends Base {}
public void cvaa()
{
- Derived[] d = new Derived[2];
- cvaa_invoke(d, 5);
- Base[] b = d;
- cvaa_invoke(b, 5);
- b2 = d;
- d2 = d;
+ Derived[] d2 = new Derived[4];
+ Base[] b = d2;
+ b2 = d2;
+ Derived d = new Derived();
b[0] = new Base();
+ b[1] = doDerived();
+ b[2] = null;
+ b[3] = d;
Integer[] a = new Integer[1];
System.arraycopy(a[0], 0, a, 1, 1);
}
- private void cvaa_invoke(Base[] b, int n){
+ private Derived doDerived(){
+ return new Derived();
}
-}
+}
\ No newline at end of file
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2009-10-18 15:33:09 UTC (rev 1380)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ContraVariantArrayAssignment.java 2009-11-12 03:35:19 UTC (rev 1381)
@@ -44,12 +44,14 @@
* A[] a = b;
* a[0] = new A(); // results in ArrayStoreException (Runtime)
* </pre>
+ *
+ * Contravariant array assignments are reported as low or normal priority bugs. In cases
+ * where the detector can determine an ArrayStoreException the bug is reported with high priority.
*
*/
public class ContraVariantArrayAssignment extends BytecodeScanningDetector {
private final BugReporter bugReporter;
private final OpcodeStack stack;
- private final boolean checkMethods;
/**
* constructs a CVAA detector given the reporter to report bugs on.
@@ -59,7 +61,6 @@
public ContraVariantArrayAssignment(final BugReporter bugReporter) {
this.bugReporter = bugReporter;
stack = new OpcodeStack();
- checkMethods = System.getProperty("CCVA_CHECKMETHODS") != null;
}
/**
@@ -88,7 +89,7 @@
case ASTORE_2:
case ASTORE_3:
if(stack.getStackDepth() > 0){
- OpcodeStack.Item item = stack.getStackItem(0);
+ OpcodeStack.Item item = stack.getStackItem(0);
String sourceSignature = item.getSignature();
LocalVariable lv = getMethod().getLocalVariableTable()
.getLocalVariable(RegisterUtils.getAStoreReg(this, seen), getNextPC());
@@ -107,17 +108,31 @@
checkSignatures(sourceSignature, targetSignature);
}
break;
- case INVOKESTATIC:
- case INVOKEVIRTUAL:
- case INVOKEINTERFACE:
- case INVOKESPECIAL:
- if(checkMethods && stack.getStackDepth() > 0){
- String signature = getSigConstantOperand();
- checkMethodInvocation(signature);
+ case AASTORE:
+ OpcodeStack.Item arrayref = stack.getStackItem(2);
+ OpcodeStack.Item value = stack.getStackItem(0);
+
+ if(!value.isNull()) {
+ String sourceSignature = value.getSignature();
+ String targetSignature = arrayref.getSignature();
+ try{
+ if(Type.getType(sourceSignature) instanceof ObjectType ) {
+ ObjectType sourceType = (ObjectType) Type.getType(sourceSignature);
+ ObjectType targetType = (ObjectType) ((ArrayType) Type.getType(targetSignature)).getBasicType();
+ if(!sourceType.subclassOf(targetType)){
+ bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
}
- break;
+ break;
}
- super.sawOpcode(seen);
+ super.sawOpcode(seen);
}
finally{
stack.sawOpcode(this, seen);
@@ -144,7 +159,7 @@
if(isObjectType(sourceSignature) && isObjectType(targetSignature)){
ObjectType sourceType = (ObjectType) ((ArrayType) Type.getType(sourceSignature)).getBasicType();
ObjectType targetType = (ObjectType) ((ArrayType) Type.getType(targetSignature)).getBasicType();
- if(sourceType.subclassOf(targetType) && !targetType.subclassOf(sourceType)) {
+ if(!targetType.subclassOf(sourceType)) {
bugReporter.reportBug(new BugInstance(this, "CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
@@ -152,20 +167,10 @@
}
}
}
- }
+ }
}
catch(ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
-
- private void checkMethodInvocation(String signature) {
- Type[] types = Type.getArgumentTypes(signature);
- for(int i = 0; i < types.length; i++){
- String targetSignature = types[i].getSignature();
- OpcodeStack.Item item = stack.getStackItem(types.length - i - 1);
- String sourceSignature = item.getSignature();
- checkSignatures(sourceSignature, targetSignature);
- }
- }
-}
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|