From 3eebaf6c4ee5cbda36392fc88a5b842ba6ede9be Mon Sep 17 00:00:00 2001 From: jinweiliu Date: Sat, 22 Apr 2023 04:06:24 +0000 Subject: [PATCH] fix nullptr Signed-off-by: jinweiliu Change-Id: I8f92b54d4ae782bc847979641525e2f8e015b668 --- .../pattern/calendar/calendar_view.cpp | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_view.cpp b/frameworks/core/components_ng/pattern/calendar/calendar_view.cpp index 40bf07b6f73..fe3c76284ab 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_view.cpp +++ b/frameworks/core/components_ng/pattern/calendar/calendar_view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -135,7 +135,9 @@ void CalendarView::SetCalendarDay(const CalendarDay& calendarDay) void CalendarView::SetShowLunar(bool showLunar) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -149,7 +151,9 @@ void CalendarView::SetShowLunar(bool showLunar) void CalendarView::SetShowHoliday(bool showHoliday) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -163,7 +167,9 @@ void CalendarView::SetShowHoliday(bool showHoliday) void CalendarView::SetNeedSlide(bool needSlide) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); auto swiperFrameNode = AceType::DynamicCast(swiperNode); CHECK_NULL_VOID(swiperFrameNode); @@ -176,7 +182,9 @@ void CalendarView::SetNeedSlide(bool needSlide) void CalendarView::SetStartOfWeek(Week startOfWeek) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -190,7 +198,9 @@ void CalendarView::SetStartOfWeek(Week startOfWeek) void CalendarView::SetOffDays(const std::string& offDays) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -204,7 +214,9 @@ void CalendarView::SetOffDays(const std::string& offDays) void CalendarView::SetDirection(Axis direction) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); auto swiperFrameNode = AceType::DynamicCast(swiperNode); CHECK_NULL_VOID(swiperFrameNode); @@ -217,7 +229,9 @@ void CalendarView::SetDirection(Axis direction) void CalendarView::SetCurrentDayStyle(const CurrentDayStyle& currentDayStyle) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -299,7 +313,9 @@ void CalendarView::SetCurrentDayStyle(const CurrentDayStyle& currentDayStyle) void CalendarView::SetNonCurrentDayStyle(const NonCurrentDayStyle& nonCurrentDayStyle) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -327,7 +343,9 @@ void CalendarView::SetNonCurrentDayStyle(const NonCurrentDayStyle& nonCurrentDay void CalendarView::SetTodayStyle(const TodayStyle& todayStyle) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -352,7 +370,9 @@ void CalendarView::SetTodayStyle(const TodayStyle& todayStyle) void CalendarView::SetWeekStyle(const WeekStyle& weekStyle) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -386,7 +406,9 @@ void CalendarView::SetWeekStyle(const WeekStyle& weekStyle) void CalendarView::SetWorkStateStyle(const WorkStateStyle& workStateStyle) { auto* stack = ViewStackProcessor::GetInstance(); - auto swiperNode = stack->GetMainFrameNode()->GetChildren().front(); + auto frameNode = stack->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto swiperNode = frameNode->GetChildren().front(); CHECK_NULL_VOID(swiperNode); for (const auto& calendarNode : swiperNode->GetChildren()) { auto calendarFrameNode = AceType::DynamicCast(calendarNode); @@ -444,4 +466,4 @@ void CalendarView::SetOnRequestDataEvent(std::function eventHub->SetOnRequestDataEvent(std::move(requestDataEvent)); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG -- Gitee