size = Integer.valueOf(getIntConstant()); sizeSet = true; break; modifyRegs.set(getRegisterOperand()); break; OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() == null) { modifyRegs.set(getRegisterOperand()); Constant c = getConstantRefOperand(); if (c instanceof ConstantInteger) { size = Integer.valueOf(((ConstantInteger) c).getBytes()); case CASTORE: case SASTORE: processArrayStore(); break; case CALOAD: case SALOAD: processArrayLoad(); break; OpcodeStack.Item value = stack.getStackItem(0); if (!value.isNull()) { initializedRegs.set(getRegisterOperand());
private void processArrayStore() { if (stack.getStackDepth() >= 3) { OpcodeStack.Item indexItem = stack.getStackItem(1); Number index = (Number) indexItem.getConstant(); if (index != null) { OpcodeStack.Item arrayItem = stack.getStackItem(2); Integer sz = (Integer) arrayItem.getUserValue(); if ((sz != null) && (index.intValue() >= sz.intValue())) { bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_INDEX_OUT_OF_BOUNDS.name(), HIGH_PRIORITY).addClass(this).addMethod(this) .addSourceLine(this)); } int reg = arrayItem.getRegisterNumber(); if ((reg >= 0) && !initializedRegs.get(reg)) { nullStoreToLocation.put(Integer.valueOf(reg), Integer.valueOf(getPC())); } } } } }
/** * overrides the visitor to collect parameter registers * * @param obj * the code block of the currently parsed method */ @Override public void visitCode(Code obj) { Method m = getMethod(); stack.resetForMethodEntry(this); initializedRegs.clear(); modifyRegs.clear(); Type[] argTypes = m.getArgumentTypes(); int arg = m.isStatic() ? 0 : 1; for (Type argType : argTypes) { String argSig = argType.getSignature(); initializedRegs.set(arg); arg += SignatureUtils.getSignatureSize(argSig); } nullStoreToLocation.clear(); super.visitCode(obj); for (Integer pc : nullStoreToLocation.values()) { bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_STORE_TO_NULL_REFERENCE.name(), HIGH_PRIORITY).addClass(this).addMethod(this) .addSourceLine(this, pc.intValue())); } }
/** * overrides the visitor to collect parameter registers * * @param obj * the code block of the currently parsed method */ @Override public void visitCode(Code obj) { Method m = getMethod(); stack.resetForMethodEntry(this); initializedRegs.clear(); modifyRegs.clear(); Type[] argTypes = m.getArgumentTypes(); int arg = m.isStatic() ? 0 : 1; for (Type argType : argTypes) { String argSig = argType.getSignature(); initializedRegs.set(arg); arg += SignatureUtils.getSignatureSize(argSig); } nullStoreToLocation.clear(); super.visitCode(obj); for (Integer pc : nullStoreToLocation.values()) { bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_STORE_TO_NULL_REFERENCE.name(), HIGH_PRIORITY).addClass(this).addMethod(this) .addSourceLine(this, pc.intValue())); } }
size = Integer.valueOf(getIntConstant()); sizeSet = true; break; modifyRegs.set(getRegisterOperand()); break; OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() == null) { modifyRegs.set(getRegisterOperand()); Constant c = getConstantRefOperand(); if (c instanceof ConstantInteger) { size = Integer.valueOf(((ConstantInteger) c).getBytes()); case Const.CASTORE: case Const.SASTORE: processArrayStore(); break; case Const.CALOAD: case Const.SALOAD: processArrayLoad(); break; OpcodeStack.Item value = stack.getStackItem(0); if (!value.isNull()) { initializedRegs.set(getRegisterOperand());
private void processArrayStore() { if (stack.getStackDepth() >= 3) { OpcodeStack.Item indexItem = stack.getStackItem(1); Number index = (Number) indexItem.getConstant(); if (index != null) { OpcodeStack.Item arrayItem = stack.getStackItem(2); Integer sz = (Integer) arrayItem.getUserValue(); if ((sz != null) && (index.intValue() >= sz.intValue())) { bugReporter.reportBug(new BugInstance(this, BugType.AIOB_ARRAY_INDEX_OUT_OF_BOUNDS.name(), HIGH_PRIORITY).addClass(this).addMethod(this) .addSourceLine(this)); } int reg = arrayItem.getRegisterNumber(); if ((reg >= 0) && !initializedRegs.get(reg)) { nullStoreToLocation.put(Integer.valueOf(reg), Integer.valueOf(getPC())); } } } } }