mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 14:53:27 +01:00
adding static_assert to pod functions in string tools
This commit is contained in:
parent
83b0511731
commit
4869db702a
@ -33,6 +33,7 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <type_traits>
|
||||||
//#include <strsafe.h>
|
//#include <strsafe.h>
|
||||||
#include <boost/uuid/uuid.hpp>
|
#include <boost/uuid/uuid.hpp>
|
||||||
#include <boost/uuid/uuid_io.hpp>
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
@ -171,6 +172,7 @@ namespace string_tools
|
|||||||
template<class t_pod_type>
|
template<class t_pod_type>
|
||||||
bool parse_tpod_from_hex_string(const std::string& str_hash, t_pod_type& t_pod)
|
bool parse_tpod_from_hex_string(const std::string& str_hash, t_pod_type& t_pod)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
|
||||||
std::string buf;
|
std::string buf;
|
||||||
bool res = epee::string_tools::parse_hexstr_to_binbuff(str_hash, buf);
|
bool res = epee::string_tools::parse_hexstr_to_binbuff(str_hash, buf);
|
||||||
if (!res || buf.size() != sizeof(t_pod_type))
|
if (!res || buf.size() != sizeof(t_pod_type))
|
||||||
@ -570,6 +572,7 @@ POP_WARNINGS
|
|||||||
template<class t_pod_type>
|
template<class t_pod_type>
|
||||||
std::string pod_to_hex(const t_pod_type& s)
|
std::string pod_to_hex(const t_pod_type& s)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
|
||||||
std::string buff;
|
std::string buff;
|
||||||
buff.assign(reinterpret_cast<const char*>(&s), sizeof(s));
|
buff.assign(reinterpret_cast<const char*>(&s), sizeof(s));
|
||||||
return buff_to_hex_nodelimer(buff);
|
return buff_to_hex_nodelimer(buff);
|
||||||
@ -578,6 +581,7 @@ POP_WARNINGS
|
|||||||
template<class t_pod_type>
|
template<class t_pod_type>
|
||||||
bool hex_to_pod(const std::string& hex_str, t_pod_type& s)
|
bool hex_to_pod(const std::string& hex_str, t_pod_type& s)
|
||||||
{
|
{
|
||||||
|
static_assert(std::is_pod<t_pod_type>::value, "expected pod type");
|
||||||
std::string hex_str_tr = trim(hex_str);
|
std::string hex_str_tr = trim(hex_str);
|
||||||
if(sizeof(s)*2 != hex_str.size())
|
if(sizeof(s)*2 != hex_str.size())
|
||||||
return false;
|
return false;
|
||||||
|
@ -518,14 +518,14 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, const s
|
|||||||
}
|
}
|
||||||
else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx.vout[o].amount)
|
else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx.vout[o].amount)
|
||||||
{
|
{
|
||||||
LOG_ERROR("key image " << epee::string_tools::pod_to_hex(ki)
|
LOG_ERROR("key image " << epee::string_tools::pod_to_hex(kit->first)
|
||||||
<< " from received " << print_money(tx.vout[o].amount) << " output already exists with "
|
<< " from received " << print_money(tx.vout[o].amount) << " output already exists with "
|
||||||
<< (m_transfers[kit->second].m_spent ? "spent" : "unspent") << " "
|
<< (m_transfers[kit->second].m_spent ? "spent" : "unspent") << " "
|
||||||
<< print_money(m_transfers[kit->second].amount()) << ", received output ignored");
|
<< print_money(m_transfers[kit->second].amount()) << ", received output ignored");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_ERROR("key image " << epee::string_tools::pod_to_hex(ki)
|
LOG_ERROR("key image " << epee::string_tools::pod_to_hex(kit->first)
|
||||||
<< " from received " << print_money(tx.vout[o].amount) << " output already exists with "
|
<< " from received " << print_money(tx.vout[o].amount) << " output already exists with "
|
||||||
<< print_money(m_transfers[kit->second].amount()) << ", replacing with new output");
|
<< print_money(m_transfers[kit->second].amount()) << ", replacing with new output");
|
||||||
// The new larger output replaced a previous smaller one
|
// The new larger output replaced a previous smaller one
|
||||||
|
Loading…
Reference in New Issue
Block a user