diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-12-19 11:41:12 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-03-06 17:21:58 +0100 |
commit | 4e853aa163ddb978d25bd8b8ecfd730a1d09e051 (patch) | |
tree | f97f78650dfb96ffb43ff3fd26e4cdd1457a9952 /src | |
parent | 4f92773f9285760fe3e2eb14f5ca21de850d1955 (diff) |
src/script/script.h: endian compatibility for PUSHDATA sizes
Diffstat (limited to 'src')
-rw-r--r-- | src/script/script.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/script/script.h b/src/script/script.h index 8b36aa2f50..ed456f5c5a 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -14,6 +14,7 @@ #include <string.h> #include <string> #include <vector> +#include "crypto/common.h" static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes @@ -416,14 +417,16 @@ public: else if (b.size() <= 0xffff) { insert(end(), OP_PUSHDATA2); - unsigned short nSize = b.size(); - insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize)); + uint8_t data[2]; + WriteLE16(data, b.size()); + insert(end(), data, data + sizeof(data)); } else { insert(end(), OP_PUSHDATA4); - unsigned int nSize = b.size(); - insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize)); + uint8_t data[4]; + WriteLE32(data, b.size()); + insert(end(), data, data + sizeof(data)); } insert(end(), b.begin(), b.end()); return *this; @@ -496,15 +499,14 @@ public: { if (end() - pc < 2) return false; - nSize = 0; - memcpy(&nSize, &pc[0], 2); + nSize = ReadLE16(&pc[0]); pc += 2; } else if (opcode == OP_PUSHDATA4) { if (end() - pc < 4) return false; - memcpy(&nSize, &pc[0], 4); + nSize = ReadLE32(&pc[0]); pc += 4; } if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize) |