mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
merge bitcoin#22875: Fix Racy ParseOpCode function initialization
This commit is contained in:
parent
427d07f4db
commit
5aceee38fc
@ -19,13 +19,15 @@
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
opcodetype ParseOpCode(const std::string& s)
|
||||
class OpCodeParser
|
||||
{
|
||||
static std::map<std::string, opcodetype> mapOpNames;
|
||||
private:
|
||||
std::map<std::string, opcodetype> mapOpNames;
|
||||
|
||||
if (mapOpNames.empty()) {
|
||||
for (unsigned int op = 0; op <= MAX_OPCODE; op++) {
|
||||
public:
|
||||
OpCodeParser()
|
||||
{
|
||||
for (unsigned int op = 0; op <= MAX_OPCODE; ++op) {
|
||||
// Allow OP_RESERVED to get into mapOpNames
|
||||
if (op < OP_NOP && op != OP_RESERVED) {
|
||||
continue;
|
||||
@ -42,10 +44,19 @@ opcodetype ParseOpCode(const std::string& s)
|
||||
}
|
||||
}
|
||||
}
|
||||
opcodetype Parse(const std::string& s) const
|
||||
{
|
||||
auto it = mapOpNames.find(s);
|
||||
if (it == mapOpNames.end()) throw std::runtime_error("script parse error: unknown opcode");
|
||||
return it->second;
|
||||
}
|
||||
};
|
||||
|
||||
opcodetype ParseOpCode(const std::string& s)
|
||||
{
|
||||
static const OpCodeParser ocp;
|
||||
return ocp.Parse(s);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user