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,7 +370,8 @@ public class Program {
result = program.getResult(); result = program.getResult();
} }
if (result.getException() != null && if (result != null &&
result.getException() != null &&
result.getException() instanceof Program.OutOfGasException) { result.getException() instanceof Program.OutOfGasException) {
logger.info("contract run halted by OutOfGas: contract={}" , Hex.toHexString(toAddress)); logger.info("contract run halted by OutOfGas: contract={}" , Hex.toHexString(toAddress));
@ -380,6 +381,7 @@ public class Program {
} }
// 3. APPLY RESULTS: result.getHReturn() into out_memory allocated // 3. APPLY RESULTS: result.getHReturn() into out_memory allocated
if (result != null) {
ByteBuffer buffer = result.getHReturn(); ByteBuffer buffer = result.getHReturn();
if (buffer != null) { if (buffer != null) {
int retSize = buffer.array().length; int retSize = buffer.array().length;
@ -391,12 +393,14 @@ public class Program {
this.memorySave(outDataOffs.getData(), buffer.array()); this.memorySave(outDataOffs.getData(), buffer.array());
} }
} }
}
// 4. THE FLAG OF SUCCESS IS ONE PUSHED INTO THE STACK // 4. THE FLAG OF SUCCESS IS ONE PUSHED INTO THE STACK
trackRepository.commit(); trackRepository.commit();
stackPushOne(); stackPushOne();
// 5. REFUND THE REMAIN GAS // 5. REFUND THE REMAIN GAS
if (result != null) {
BigInteger refundGas = gas.value().subtract(BigInteger.valueOf(result.getGasUsed())); BigInteger refundGas = gas.value().subtract(BigInteger.valueOf(result.getGasUsed()));
if (refundGas.compareTo(BigInteger.ZERO) == 1) { if (refundGas.compareTo(BigInteger.ZERO) == 1) {
@ -404,7 +408,10 @@ public class Program {
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) {