NPE bug in program

This commit is contained in:
romanman 2014-07-06 19:19:49 +01:00
parent 0f2b74ebf2
commit c100e15580
1 changed files with 28 additions and 21 deletions

View File

@ -370,25 +370,28 @@ public class Program {
result = program.getResult(); result = program.getResult();
} }
if (result.getException() != null && if (result != null &&
result.getException() instanceof Program.OutOfGasException) { result.getException() != null &&
logger.info("contract run halted by OutOfGas: contract={}" , Hex.toHexString(toAddress)); result.getException() instanceof Program.OutOfGasException) {
logger.info("contract run halted by OutOfGas: contract={}" , Hex.toHexString(toAddress));
trackRepository.rollback(); trackRepository.rollback();
stackPushZero(); stackPushZero();
return; return;
} }
// 3. APPLY RESULTS: result.getHReturn() into out_memory allocated // 3. APPLY RESULTS: result.getHReturn() into out_memory allocated
ByteBuffer buffer = result.getHReturn(); if (result != null) {
if (buffer != null) { ByteBuffer buffer = result.getHReturn();
int retSize = buffer.array().length; if (buffer != null) {
int allocSize = outDataSize.intValue(); int retSize = buffer.array().length;
if (retSize > allocSize) { int allocSize = outDataSize.intValue();
byte[] outArray = Arrays.copyOf(buffer.array(), allocSize); if (retSize > allocSize) {
this.memorySave(outArray, buffer.array()); byte[] outArray = Arrays.copyOf(buffer.array(), allocSize);
} else { this.memorySave(outArray, buffer.array());
this.memorySave(outDataOffs.getData(), buffer.array()); } else {
this.memorySave(outDataOffs.getData(), buffer.array());
}
} }
} }
@ -397,14 +400,18 @@ public class Program {
stackPushOne(); stackPushOne();
// 5. REFUND THE REMAIN GAS // 5. REFUND THE REMAIN GAS
BigInteger refundGas = gas.value().subtract(BigInteger.valueOf(result.getGasUsed())); if (result != null) {
if (refundGas.compareTo(BigInteger.ZERO) == 1){ BigInteger refundGas = gas.value().subtract(BigInteger.valueOf(result.getGasUsed()));
if (refundGas.compareTo(BigInteger.ZERO) == 1) {
this.refundGas(refundGas.intValue(), "remain gas from the internal call"); this.refundGas(refundGas.intValue(), "remain gas from the internal call");
logger.info("The remain gas refunded, account: [ {} ], gas: [ {} ] ", logger.info("The remain gas refunded, account: [ {} ], gas: [ {} ] ",
refundGas.toString(), refundGas.toString()); refundGas.toString(), refundGas.toString());
}
} else {
this.refundGas(gas.intValue(), "remain gas from the internal call");
} }
} }
public void spendGas(int gasValue, String cause) { public void spendGas(int gasValue, String cause) {