aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Sanders <gsanders87@gmail.com>2019-05-31 10:01:15 -0400
committerGregory Sanders <gsanders87@gmail.com>2019-06-13 09:27:14 -0400
commite1a55690e66ca962179bc8170695b92af8a3caa8 (patch)
treec1541588ea72b1b24a538b902cc59b46637beda0 /src
parentc7cfd20a77ce57d200b3b9e5e0dfb0d63818abdc (diff)
downloadbitcoin-e1a55690e66ca962179bc8170695b92af8a3caa8.tar.xz
Delete error-prone CScript constructor
Diffstat (limited to 'src')
-rw-r--r--src/qt/coincontroldialog.cpp6
-rw-r--r--src/script/interpreter.cpp4
-rw-r--r--src/script/script.h4
3 files changed, 9 insertions, 5 deletions
diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp
index 6c9bae7673..d5dd62178f 100644
--- a/src/qt/coincontroldialog.cpp
+++ b/src/qt/coincontroldialog.cpp
@@ -422,7 +422,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
if (amount > 0)
{
- CTxOut txout(amount, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
+ // Assumes a p2pkh script size
+ CTxOut txout(amount, CScript() << std::vector<unsigned char>(24, 0));
txDummy.vout.push_back(txout);
fDust |= IsDust(txout, model->node().getDustRelayFee());
}
@@ -513,7 +514,8 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
// Never create dust outputs; if we would, just add the dust to the fee.
if (nChange > 0 && nChange < MIN_CHANGE)
{
- CTxOut txout(nChange, static_cast<CScript>(std::vector<unsigned char>(24, 0)));
+ // Assumes a p2pkh script size
+ CTxOut txout(nChange, CScript() << std::vector<unsigned char>(24, 0));
if (IsDust(txout, model->node().getDustRelayFee()))
{
nPayFee += nChange;
diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp
index 95b25b4911..f8701b6d01 100644
--- a/src/script/interpreter.cpp
+++ b/src/script/interpreter.cpp
@@ -926,7 +926,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
// Drop the signature in pre-segwit scripts but not segwit scripts
if (sigversion == SigVersion::BASE) {
- int found = FindAndDelete(scriptCode, CScript(vchSig));
+ int found = FindAndDelete(scriptCode, CScript() << vchSig);
if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE);
}
@@ -992,7 +992,7 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
{
valtype& vchSig = stacktop(-isig-k);
if (sigversion == SigVersion::BASE) {
- int found = FindAndDelete(scriptCode, CScript(vchSig));
+ int found = FindAndDelete(scriptCode, CScript() << vchSig);
if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE);
}
diff --git a/src/script/script.h b/src/script/script.h
index 11e8661a5b..6355b8a704 100644
--- a/src/script/script.h
+++ b/src/script/script.h
@@ -437,7 +437,9 @@ public:
explicit CScript(opcodetype b) { operator<<(b); }
explicit CScript(const CScriptNum& b) { operator<<(b); }
- explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
+ // delete non-existent constructor to defend against future introduction
+ // e.g. via prevector
+ explicit CScript(const std::vector<unsigned char>& b) = delete;
CScript& operator<<(int64_t b) { return push_int64(b); }