由于合约中使用nlohmann/json
解析json时,当遇到float类型时报"wabt out of bounds memory access"
不断调试代码,找到如下位置
https://github.com/nlohmann/json/blob/d2a08ddafd503b02b3418194c31e121e105411c6/include/nlohmann/detail/input/lexer.hpp#L1005
由于合约内不会考虑float类型,项目较急,先直接不解析此类型,下面位置添加return token_type::parse_error;
scan_number_decimal1:
return token_type::parse_error; //在这加一个return
// state: we just parsed a decimal point
number_type = token_type::value_float;
switch (get())
{
case '0':
case '1':
case '2':
case '3':
并且由于合约内不允许使用try,修改下
https://github.com/nlohmann/json/blob/b52c3638f58291c2f2564aa31ad0a4a15cd01c84/include/nlohmann/detail/macro_scope.hpp#L68
// allow to disable exceptions
#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
// #define JSON_THROW(exception) throw exception 修改为如下
#define JSON_THROW(exception) eosio_assert(false, exception.c_str());
#define JSON_TRY try
#define JSON_CATCH(exception) catch(exception)
#define JSON_INTERNAL_CATCH(exception) catch(exception)
#else
#include <cstdlib>
// #define JSON_THROW(exception) std::abort() 修改为如下
#define JSON_THROW(exception) eosio_assert(false, exception.c_str());
#define JSON_TRY if(true)
#define JSON_CATCH(exception) if(false)
#define JSON_INTERNAL_CATCH(exception) if(false)
#endif
// override exception macros
#if defined(JSON_THROW_USER)
#undef JSON_THROW
#define JSON_THROW JSON_THROW_USER
#endif
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://bcskill.com/index.php/archives/714.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!