Better algorithm validation.

This commit is contained in:
XMRig 2018-04-25 22:03:26 +07:00
parent a9cc5c5258
commit 230962230f
3 changed files with 29 additions and 2 deletions

View file

@ -79,6 +79,22 @@ static const char *variants[] = {
};
bool xmrig::Algorithm::isValid() const
{
if (m_algo == INVALID_ALGO) {
return false;
}
for (size_t i = 0; i < ARRAY_SIZE(algorithms); i++) {
if (algorithms[i].algo == m_algo && algorithms[i].variant == m_variant) {
return true;
}
}
return false;
}
const char *xmrig::Algorithm::variantName() const
{
if (m_variant == VARIANT_AUTO) {

View file

@ -48,7 +48,6 @@ public:
bool isEqual(const Algorithm &other) const { return m_algo == other.m_algo && m_variant == other.m_variant; }
inline Algo algo() const { return m_algo; }
inline bool isValid() const { return m_algo != INVALID_ALGO; }
inline const char *name() const { return name(false); }
inline const char *shortName() const { return name(true); }
inline Variant variant() const { return m_variant; }
@ -57,6 +56,7 @@ public:
inline bool operator!=(const Algorithm &other) const { return !isEqual(other); }
inline bool operator==(const Algorithm &other) const { return isEqual(other); }
bool isValid() const;
const char *variantName() const;
void parseAlgorithm(const char *algo);
void parseVariant(const char *variant);

View file

@ -164,7 +164,18 @@ xmrig::CpuThread::cn_hash_fun xmrig::CpuThread::fn(Algo algorithm, AlgoVariant a
}
# endif
return func_table[40 * algorithm + 10 * variant + av - 1];
const size_t index = 40 * algorithm + 10 * variant + av - 1;
# ifndef NDEBUG
cn_hash_fun func = func_table[index];
assert(index < sizeof(func_table) / sizeof(func_table[0]));
assert(func != nullptr);
return func;
# else
return func_table[index];
# endif
}