diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-06 11:46:41 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-13 18:05:39 +0200 |
commit | fa277cd55dd105018e7d1220b4c3d96779e6b0f4 (patch) | |
tree | 7b07f6268287e14da3bd5184f40b7975a9459582 /src/univalue/lib/univalue.cpp | |
parent | ccccc17b91698aa09ac85f7efea298f3938594ad (diff) | |
download | bitcoin-fa277cd55dd105018e7d1220b4c3d96779e6b0f4.tar.xz |
univalue: Throw exception on invalid pushes over silent ignore
Diffstat (limited to 'src/univalue/lib/univalue.cpp')
-rw-r--r-- | src/univalue/lib/univalue.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index 3553995c28..ac6f31a5a9 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -108,53 +108,45 @@ bool UniValue::setObject() return true; } -bool UniValue::push_back(const UniValue& val_) +void UniValue::push_back(const UniValue& val_) { - if (typ != VARR) - return false; + if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"}; values.push_back(val_); - return true; } -bool UniValue::push_backV(const std::vector<UniValue>& vec) +void UniValue::push_backV(const std::vector<UniValue>& vec) { - if (typ != VARR) - return false; + if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"}; values.insert(values.end(), vec.begin(), vec.end()); - - return true; } void UniValue::__pushKV(const std::string& key, const UniValue& val_) { + if (typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"}; + keys.push_back(key); values.push_back(val_); } -bool UniValue::pushKV(const std::string& key, const UniValue& val_) +void UniValue::pushKV(const std::string& key, const UniValue& val_) { - if (typ != VOBJ) - return false; + if (typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"}; size_t idx; if (findKey(key, idx)) values[idx] = val_; else __pushKV(key, val_); - return true; } -bool UniValue::pushKVs(const UniValue& obj) +void UniValue::pushKVs(const UniValue& obj) { - if (typ != VOBJ || obj.typ != VOBJ) - return false; + if (typ != VOBJ || obj.typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"}; for (size_t i = 0; i < obj.keys.size(); i++) __pushKV(obj.keys[i], obj.values.at(i)); - - return true; } void UniValue::getObjMap(std::map<std::string,UniValue>& kv) const |