mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
parseJSON: Ensure NULL values from failed lookups do not persist
The operator[] insets values if the lookup fails, which creates null pointers. See: https://en.cppreference.com/w/cpp/container/map/operator_at
This commit is contained in:
parent
75422e80e3
commit
6d81acd355
1 changed files with 9 additions and 4 deletions
13
src/Task.cpp
13
src/Task.cpp
|
@ -757,14 +757,19 @@ void Task::parseJSON (const json::object* root_obj)
|
||||||
for (auto& annotations : atts->_data)
|
for (auto& annotations : atts->_data)
|
||||||
{
|
{
|
||||||
auto annotation = (json::object*)annotations;
|
auto annotation = (json::object*)annotations;
|
||||||
|
|
||||||
auto when = (json::string*)annotation->_data["entry"];
|
auto when = (json::string*)annotation->_data["entry"];
|
||||||
auto what = (json::string*)annotation->_data["description"];
|
auto what = (json::string*)annotation->_data["description"];
|
||||||
|
|
||||||
if (! when)
|
if (! when) {
|
||||||
throw format ("Annotation is missing an entry date: {1}", root_obj-> dump ());
|
annotation->_data.erase ("entry"); // Erase NULL entry inserted by failed lookup above
|
||||||
|
throw format ("Annotation is missing an entry date: {1}", annotation-> dump ());
|
||||||
|
}
|
||||||
|
|
||||||
if (! what)
|
if (! what) {
|
||||||
throw format ("Annotation is missing a description: {1}", root_obj->dump ());
|
annotation->_data.erase ("description"); // Erase NULL description inserted by failed lookup above
|
||||||
|
throw format ("Annotation is missing a description: {1}", annotation->dump ());
|
||||||
|
}
|
||||||
|
|
||||||
// Extract 64-bit annotation entry value
|
// Extract 64-bit annotation entry value
|
||||||
// Time travelers from 2038, we have your back.
|
// Time travelers from 2038, we have your back.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue