UILabelExt sLabeldata; // 标签
UILabelExt sLabeltime; // 标签
UIImageView slogo; // 图标
- TraingRecordItem sItemInfo = {0, nullptr, nullptr, nullptr};
+ TraingRecordItem sItemInfo = {-1, "", "", ""}; // index=-1 表示未设置,避免误用导致越界
};
}
}
else
{
- TraingRecordItemView *p_TraingRecordItemView = static_cast<TraingRecordItemView *>(&view);
+ TraingRecordItemView *p_TraingRecordItemView = dynamic_cast<TraingRecordItemView *>(&view);
+ if (p_TraingRecordItemView == nullptr)
+ {
+ return false;
+ }
int index = p_TraingRecordItemView->GetTraingRecordIndex();
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the index is %d", index);
- // 读取json数据
std::vector<SportData> sportDataVector;
if (!TraingModel::GetInstance()->LoadDataFormJson(sportDataVector))
{
}
if (!sportDataVector.empty())
{
- // 选择点击按键的历史数据
- int arraynum = sportDataVector.size() - 1;
+ int arraynum = static_cast<int>(sportDataVector.size()) - 1;
+ if (index < 0 || index > arraynum)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "invalid record index %d, size=%zu", index, sportDataVector.size());
+ return false;
+ }
SportData sportData = sportDataVector[arraynum - index]; // 显示是倒序 id同理
// 先设置运动数据,确保sportId_被正确更新,然后再进入界面
// 这样OnStart()中调用IsNeedGPS()时能正确判断