Skip to content

Commit

Permalink
Avoid crashes in DataFilter when athlete has no activities
Browse files Browse the repository at this point in the history
DataFilter evaluation requires an activity to get context,
so don't try to evaluate one when there is no current activity
to avoid crashes. It is a marginal edge case without practical
value, but better don't crash when a new user is playing around.
  • Loading branch information
amtriathlon committed Oct 13, 2021
1 parent 289962c commit 007dc4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Charts/OverviewItems.cpp
Expand Up @@ -1032,7 +1032,7 @@ DataOverviewItem::setData(RideItem *item)
DataFilter parser(this, item->context, program);

// so long as it evaluated correctly we can call the functions
if (parser.root() && parser.errorList().isEmpty()) {
if (parser.root() && parser.errorList().isEmpty() && parent->context->currentRideItem()) {

Specification spec;
DateRange dr;
Expand Down Expand Up @@ -1303,7 +1303,7 @@ DataOverviewItem::setDateRange(DateRange dr)
DataFilter parser(this, parent->context, program);

// so long as it evaluated correctly we can call the functions
if (parser.root() && parser.errorList().isEmpty()) {
if (parser.root() && parser.errorList().isEmpty() && parent->context->currentRideItem()) {

Specification spec;
spec.setDateRange(dr);
Expand Down
10 changes: 4 additions & 6 deletions src/Core/DataFilter.cpp
Expand Up @@ -3116,7 +3116,10 @@ Result DataFilter::evaluate(RideItem *item, RideFilePoint *p)

Result DataFilter::evaluate(Specification spec, DateRange dr)
{
if (!treeRoot || DataFiltererrors.count()) return Result(0);
// if there is no current ride item then there is no data
// so it really is ok to baulk at no current ride item here
// we must always have a ride since context is used
if (context->currentRideItem() == NULL || !treeRoot || DataFiltererrors.count()) return Result(0);

Result res(0);

Expand All @@ -3138,11 +3141,6 @@ Result DataFilter::evaluate(Specification spec, DateRange dr)

Result DataFilter::evaluate(DateRange dr, QString filter)
{
// if there is no current ride item then there is no data
// so it really is ok to baulk at no current ride item here
// we must always have a ride since context is used
if (context->currentRideItem() == NULL || !treeRoot || DataFiltererrors.count()) return Result(0);

// reset stack
rt.stack = 0;

Expand Down

0 comments on commit 007dc4b

Please sign in to comment.