mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 19:10:11 +08:00
refactor: check (always-valid) ptr before deref
This commit is contained in:
@@ -1161,7 +1161,12 @@ template<typename Value, typename Iterator>
|
|||||||
bool is_valid_forward_table_definition(const Value& fwd,
|
bool is_valid_forward_table_definition(const Value& fwd,
|
||||||
Iterator key_first, Iterator key_curr, Iterator key_last)
|
Iterator key_first, Iterator key_curr, Iterator key_last)
|
||||||
{
|
{
|
||||||
location def("internal", detail::get_region(fwd)->str());
|
std::string internal = "";
|
||||||
|
if(const auto ptr = detail::get_region(fwd))
|
||||||
|
{
|
||||||
|
internal = ptr->str();
|
||||||
|
}
|
||||||
|
location def("internal", std::move(internal));
|
||||||
if(const auto tabkeys = parse_table_key(def))
|
if(const auto tabkeys = parse_table_key(def))
|
||||||
{
|
{
|
||||||
// table keys always contains all the nodes from the root.
|
// table keys always contains all the nodes from the root.
|
||||||
@@ -1283,12 +1288,14 @@ insert_nested_key(typename Value::table_type& root, const Value& v,
|
|||||||
// that points to the key of the table (e.g. [[a]]). By
|
// that points to the key of the table (e.g. [[a]]). By
|
||||||
// comparing the first two letters in key, we can detect
|
// comparing the first two letters in key, we can detect
|
||||||
// the array-of-table is inline or multiline.
|
// the array-of-table is inline or multiline.
|
||||||
if(detail::get_region(a.front())->str().substr(0,2) != "[[")
|
if(const auto ptr = detail::get_region(a.front()))
|
||||||
|
{
|
||||||
|
if(ptr->str().substr(0,2) != "[[")
|
||||||
{
|
{
|
||||||
throw syntax_error(format_underline(concat_to_string(
|
throw syntax_error(format_underline(concat_to_string(
|
||||||
"toml::insert_value: array of table (\"",
|
"toml::insert_value: array of table (\"",
|
||||||
format_dotted_keys(first, last), "\") collides with"
|
format_dotted_keys(first, last), "\") collides "
|
||||||
" existing array-of-tables"), {
|
"with existing array-of-tables"), {
|
||||||
{get_region(tab->at(k)),
|
{get_region(tab->at(k)),
|
||||||
concat_to_string("this ", tab->at(k).type(),
|
concat_to_string("this ", tab->at(k).type(),
|
||||||
" value has static size")},
|
" value has static size")},
|
||||||
@@ -1296,6 +1303,7 @@ insert_nested_key(typename Value::table_type& root, const Value& v,
|
|||||||
"appending it to the statically sized array"}
|
"appending it to the statically sized array"}
|
||||||
}), v.location());
|
}), v.location());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
a.push_back(v);
|
a.push_back(v);
|
||||||
return ok(true);
|
return ok(true);
|
||||||
}
|
}
|
||||||
@@ -1379,10 +1387,11 @@ insert_nested_key(typename Value::table_type& root, const Value& v,
|
|||||||
// According to toml-lang/toml:36d3091b3 "Clarify that inline
|
// According to toml-lang/toml:36d3091b3 "Clarify that inline
|
||||||
// tables are immutable", check if it adds key-value pair to an
|
// tables are immutable", check if it adds key-value pair to an
|
||||||
// inline table.
|
// inline table.
|
||||||
|
if(const auto* ptr = get_region(tab->at(k)))
|
||||||
{
|
{
|
||||||
// here, if the value is a (multi-line) table, the region
|
// here, if the value is a (multi-line) table, the region
|
||||||
// should be something like `[table-name]`.
|
// should be something like `[table-name]`.
|
||||||
if(get_region(tab->at(k))->front() == '{')
|
if(ptr->front() == '{')
|
||||||
{
|
{
|
||||||
throw syntax_error(format_underline(concat_to_string(
|
throw syntax_error(format_underline(concat_to_string(
|
||||||
"toml::insert_value: inserting to an inline table (",
|
"toml::insert_value: inserting to an inline table (",
|
||||||
|
Reference in New Issue
Block a user