mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
fix: use sscanf_s in case of MSVC
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
namespace toml
|
namespace toml
|
||||||
{
|
{
|
||||||
@@ -155,7 +156,11 @@ read_int(const std::string& str, const source_location src, const std::uint8_t b
|
|||||||
inline result<float, error_info>
|
inline result<float, error_info>
|
||||||
read_hex_float(const std::string& str, const source_location src, float val)
|
read_hex_float(const std::string& str, const source_location src, float val)
|
||||||
{
|
{
|
||||||
|
#if defined(_MSC_VER) && ! defined(__clang__)
|
||||||
|
const auto res = ::sscanf_s(str.c_str(), "%a", std::addressof(val));
|
||||||
|
#else
|
||||||
const auto res = std::sscanf(str.c_str(), "%a", std::addressof(val));
|
const auto res = std::sscanf(str.c_str(), "%a", std::addressof(val));
|
||||||
|
#endif
|
||||||
if(res != 1)
|
if(res != 1)
|
||||||
{
|
{
|
||||||
return err(make_error_info("toml::parse_floating: "
|
return err(make_error_info("toml::parse_floating: "
|
||||||
@@ -167,7 +172,11 @@ read_hex_float(const std::string& str, const source_location src, float val)
|
|||||||
inline result<double, error_info>
|
inline result<double, error_info>
|
||||||
read_hex_float(const std::string& str, const source_location src, double val)
|
read_hex_float(const std::string& str, const source_location src, double val)
|
||||||
{
|
{
|
||||||
|
#if defined(_MSC_VER) && ! defined(__clang__)
|
||||||
|
const auto res = ::sscanf_s(str.c_str(), "%la", std::addressof(val));
|
||||||
|
#else
|
||||||
const auto res = std::sscanf(str.c_str(), "%la", std::addressof(val));
|
const auto res = std::sscanf(str.c_str(), "%la", std::addressof(val));
|
||||||
|
#endif
|
||||||
if(res != 1)
|
if(res != 1)
|
||||||
{
|
{
|
||||||
return err(make_error_info("toml::parse_floating: "
|
return err(make_error_info("toml::parse_floating: "
|
||||||
|
|||||||
Reference in New Issue
Block a user