Fixed several issues with clocking out in a timelog, which was leading to an
invalid memory access.
This commit is contained in:
parent
78813fc616
commit
a210e8ba56
1 changed files with 32 additions and 15 deletions
47
textual.cc
47
textual.cc
|
|
@ -43,8 +43,17 @@ struct time_entry_t {
|
||||||
datetime_t checkin;
|
datetime_t checkin;
|
||||||
account_t * account;
|
account_t * account;
|
||||||
std::string desc;
|
std::string desc;
|
||||||
|
|
||||||
|
time_entry_t() : account(NULL) {}
|
||||||
|
time_entry_t(datetime_t _checkin,
|
||||||
|
account_t * _account = NULL,
|
||||||
|
std::string _desc = "")
|
||||||
|
: checkin(_checkin), account(_account), desc(_desc) {}
|
||||||
|
|
||||||
|
time_entry_t(const time_entry_t& entry)
|
||||||
|
: checkin(entry.checkin), account(entry.account),
|
||||||
|
desc(entry.desc) {}
|
||||||
};
|
};
|
||||||
std::list<time_entry_t> time_entries;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline char * next_element(char * buf, bool variable = false)
|
inline char * next_element(char * buf, bool variable = false)
|
||||||
|
|
@ -496,10 +505,11 @@ bool textual_parser_t::test(std::istream& in) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clock_out_from_timelog(const datetime_t& when,
|
static void clock_out_from_timelog(std::list<time_entry_t>& time_entries,
|
||||||
account_t * account,
|
const datetime_t& when,
|
||||||
const char * desc,
|
account_t * account,
|
||||||
journal_t * journal)
|
const char * desc,
|
||||||
|
journal_t * journal)
|
||||||
{
|
{
|
||||||
time_entry_t event;
|
time_entry_t event;
|
||||||
|
|
||||||
|
|
@ -576,8 +586,9 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
TIMER_START(parsing_total);
|
TIMER_START(parsing_total);
|
||||||
|
|
||||||
std::list<account_t *> account_stack;
|
std::list<account_t *> account_stack;
|
||||||
auto_entry_finalizer_t auto_entry_finalizer(journal);
|
auto_entry_finalizer_t auto_entry_finalizer(journal);
|
||||||
|
std::list<time_entry_t> time_entries;
|
||||||
|
|
||||||
if (! master)
|
if (! master)
|
||||||
master = journal->master;
|
master = journal->master;
|
||||||
|
|
@ -621,10 +632,8 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
char * p = skip_ws(line + 22);
|
char * p = skip_ws(line + 22);
|
||||||
char * n = next_element(p, true);
|
char * n = next_element(p, true);
|
||||||
|
|
||||||
time_entry_t event;
|
time_entry_t event(date, account_stack.front()->find_account(p),
|
||||||
event.desc = n ? n : "";
|
n ? n : "");
|
||||||
event.checkin = date;
|
|
||||||
event.account = account_stack.front()->find_account(p);
|
|
||||||
|
|
||||||
if (! time_entries.empty())
|
if (! time_entries.empty())
|
||||||
for (std::list<time_entry_t>::iterator i = time_entries.begin();
|
for (std::list<time_entry_t>::iterator i = time_entries.begin();
|
||||||
|
|
@ -649,8 +658,8 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
char * n = next_element(p, true);
|
char * n = next_element(p, true);
|
||||||
|
|
||||||
clock_out_from_timelog
|
clock_out_from_timelog
|
||||||
(date, p ? account_stack.front()->find_account(p) : NULL, n,
|
(time_entries, date,
|
||||||
journal);
|
p ? account_stack.front()->find_account(p) : NULL, n, journal);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -886,11 +895,19 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (! time_entries.empty()) {
|
if (! time_entries.empty()) {
|
||||||
|
std::list<account_t *> accounts;
|
||||||
|
|
||||||
for (std::list<time_entry_t>::iterator i = time_entries.begin();
|
for (std::list<time_entry_t>::iterator i = time_entries.begin();
|
||||||
i != time_entries.end();
|
i != time_entries.end();
|
||||||
i++)
|
i++)
|
||||||
clock_out_from_timelog(datetime_t::now, (*i).account, NULL, journal);
|
accounts.push_back((*i).account);
|
||||||
time_entries.clear();
|
|
||||||
|
for (std::list<account_t *>::iterator i = accounts.begin();
|
||||||
|
i != accounts.end();
|
||||||
|
i++)
|
||||||
|
clock_out_from_timelog(time_entries, datetime_t::now, *i, NULL, journal);
|
||||||
|
|
||||||
|
assert(time_entries.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (added_auto_entry_hook)
|
if (added_auto_entry_hook)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue