From: CryptoManiac Date: Mon, 11 Apr 2016 21:02:17 +0000 (+0300) Subject: Use type-safe enum for opcodes. X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=eadd29fd174e943eb82c5000e228fef07bf1f5a4 Use type-safe enum for opcodes. --- diff --git a/src/script.cpp b/src/script.cpp index 89b3e98..379923f 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -459,7 +459,7 @@ bool EvalScript(vector >& stack, const CScript& script, co opcode == OP_RSHIFT) return false; // Disabled opcodes. - if (fExec && 0 <= opcode && opcode <= OP_PUSHDATA4) + if (fExec && opcode <= OP_PUSHDATA4) stack.push_back(vchPushValue); else if (fExec || (OP_IF <= opcode && opcode <= OP_ENDIF)) switch (opcode) @@ -486,7 +486,7 @@ bool EvalScript(vector >& stack, const CScript& script, co case OP_16: { // ( -- value) - CBigNum bn((int)opcode - (int)(OP_1 - 1)); + CBigNum bn(opcode - (OP_1 - 1)); stack.push_back(bn.getvch()); } break; diff --git a/src/script.h b/src/script.h index 5a3cf06..7355f67 100644 --- a/src/script.h +++ b/src/script.h @@ -109,7 +109,7 @@ enum txnouttype const char* GetTxnOutputType(txnouttype t); // Script opcodes -enum opcodetype +enum opcodetype : uint8_t { // push value OP_0 = 0x00, @@ -356,9 +356,7 @@ public: CScript& operator<<(opcodetype opcode) { - if (opcode < 0 || opcode > 0xff) - throw std::runtime_error("CScript::operator<<() : invalid opcode"); - insert(end(), (uint8_t)opcode); + insert(end(), opcode); return *this; } @@ -607,7 +605,7 @@ public: str += "[error]"; return str; } - if (0 <= opcode && opcode <= OP_PUSHDATA4) + if (opcode <= OP_PUSHDATA4) str += fShort? ValueString(vch).substr(0, 10) : ValueString(vch); else str += GetOpName(opcode);