[bitcoin/bitcoin] script: Avoid side effect in RHS operand (MISRA-C). Clarify intended logic. (#13684)

FWIW, both `clang -O` and `gcc -O` generates the same assembly for the before/after code.

Some history from `git` history:

Satoshi introduced this code in 6ff5f718b6a67797b2b3bab8905d607ad216ee21 (2010).

@petertodd added a clarifying comment in 214d45b6b9a4f25d7d8bd4e5443fa2bee485353a (2013):

commit 214d45b6b9a4f25d7d8bd4e5443fa2bee485353a
Author: Peter Todd

Document and test OP_RESERVED weirdness

Seems it was forgotten about when IsPushOnly() and the unittests were
written. A particular oddity is that OP_RESERVED doesn’t count towards
the >201 opcode limit unlike every other named opcode.

diff —git a/src/script.cpp b/src/script.cpp
index 2df2e9f0d..a3aae42d2 100644
— a/src/script.cpp
+++ b/src/script.cpp
@@ -327,6 +327,8 @@ bool EvalScript(vector >& stack, const CScript& script, co
return false;
if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE)
return false;
+ // Note how OP_RESERVED does not count towards the opcode limit.
if (opcode > OP_16 && ++nOpCount > 201)
return false;

Добавить комментарий