From da05d8f43e988ed14f05575384a69f4f2a93437f Mon Sep 17 00:00:00 2001 From: benb365 Date: Tue, 29 Mar 2022 16:15:59 +0800 Subject: [PATCH] Fix code review issues. Signed-off-by: benb365 --- ai/cv/image_classification/resize_computer.cpp | 2 +- launcher/launcher/src/main/cpp/app_manage.cpp | 8 ++++---- launcher/launcher/src/main/cpp/swipe_view.cpp | 9 ++++++--- launcher/launcher/src/main/cpp/swipe_view.h | 4 +++- launcher/launcher/src/main/cpp/time_weather_view.cpp | 5 +---- setting/setting/src/main/cpp/app_ability_slice.cpp | 1 - setting/setting/src/main/cpp/app_info_ability_slice.cpp | 7 +++++-- setting/setting/src/main/cpp/main_ability_slice.cpp | 4 ++-- .../src/main/cpp/setting_display_ability_slice.cpp | 4 ---- setting/setting/src/main/cpp/wpa_work.c | 4 +--- 10 files changed, 23 insertions(+), 25 deletions(-) diff --git a/ai/cv/image_classification/resize_computer.cpp b/ai/cv/image_classification/resize_computer.cpp index c119b5c..d01aac6 100644 --- a/ai/cv/image_classification/resize_computer.cpp +++ b/ai/cv/image_classification/resize_computer.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "ic_retcode.h" #include "resize_computer.h" +#include "ic_retcode.h" namespace IC { const int RESIZE_CONSTANT = 2; diff --git a/launcher/launcher/src/main/cpp/app_manage.cpp b/launcher/launcher/src/main/cpp/app_manage.cpp index 8cfd7fa..d3cf1b7 100755 --- a/launcher/launcher/src/main/cpp/app_manage.cpp +++ b/launcher/launcher/src/main/cpp/app_manage.cpp @@ -42,16 +42,16 @@ bool AppManage::GetAailityInfosByBundleName(const char* bundleName, AppInfo* pAp BundleInfo* pBundleInfo = pBundleInfos; for (int i = 0; i < count; i++, pBundleInfo++) { if (memcmp(bundleName, pBundleInfo->bundleName, strlen(pBundleInfo->bundleName)) == 0) { - memcpy_s( + (void)memcpy_s( pApp->appName_, sizeof(pApp->appName_), pBundleInfo->bundleName, strlen(pBundleInfo->bundleName)); pApp->appName_[strlen(pBundleInfo->bundleName)] = 0; if (pBundleInfo->abilityInfos[0].name) { - memcpy_s(pApp->abilityName_, sizeof(pApp->abilityName_), pBundleInfo->abilityInfos[0].name, + (void)memcpy_s(pApp->abilityName_, sizeof(pApp->abilityName_), pBundleInfo->abilityInfos[0].name, strlen(pBundleInfo->abilityInfos[0].name)); pApp->abilityName_[strlen(pBundleInfo->abilityInfos[0].name)] = 0; } if (pBundleInfo->bigIconPath) { - memcpy_s(pApp->appIconDir_, sizeof(pApp->appIconDir_), pBundleInfo->bigIconPath, + (void)memcpy_s(pApp->appIconDir_, sizeof(pApp->appIconDir_), pBundleInfo->bigIconPath, strlen(pBundleInfo->bigIconPath)); pApp->appIconDir_[strlen(pBundleInfo->bigIconPath)] = 0; } @@ -106,7 +106,7 @@ void AppManage::MyBundleStateCallback( void AppManage::MyBundleOwnCallback(const uint8_t resultCode, const void* resultMessage) { - // todo uninstall callback + // uninstall callback } bool AppManage::LauncherApp(BundleInfo** info, int& count) diff --git a/launcher/launcher/src/main/cpp/swipe_view.cpp b/launcher/launcher/src/main/cpp/swipe_view.cpp index 1fe5348..785973e 100755 --- a/launcher/launcher/src/main/cpp/swipe_view.cpp +++ b/launcher/launcher/src/main/cpp/swipe_view.cpp @@ -59,6 +59,9 @@ UIViewGroup* SwipeView::AddViewGroup() return nullptr; } UIViewGroup* viewGroup = new UIViewGroup(); + if (viewGroup == nullptr) { + return viewGroup; + } viewGroup->SetPosition(0, LABLE_TITLE_HEIGHT, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight() - LABLE_TITLE_HEIGHT - LABLE_TAIL_HEIGHT); viewGroup->SetStyle(STYLE_BACKGROUND_OPA, TOTAL_OPACITY); @@ -135,17 +138,17 @@ void SwipeView::OnSetUpView() app->funcclick_ = AppEvent::ClickEvent; app->funclPress_ = AppEvent::LongPressEvent; if (pBundleInfos[j].bundleName) { - memcpy_s(app->appName_, sizeof(app->appName_), pBundleInfos[j].bundleName, + (void)memcpy_s(app->appName_, sizeof(app->appName_), pBundleInfos[j].bundleName, strlen(pBundleInfos[j].bundleName)); app->appName_[strlen(pBundleInfos[j].bundleName)] = 0; } if (pBundleInfos[j].abilityInfos[0].name) { - memcpy_s(app->abilityName_, sizeof(app->abilityName_), pBundleInfos[j].abilityInfos[0].name, + (void)memcpy_s(app->abilityName_, sizeof(app->abilityName_), pBundleInfos[j].abilityInfos[0].name, strlen(pBundleInfos[j].abilityInfos[0].name)); app->abilityName_[strlen(pBundleInfos[j].abilityInfos[0].name)] = 0; } if (pBundleInfos[j].bigIconPath) { - memcpy_s(app->appIconDir_, sizeof(app->appIconDir_), pBundleInfos[j].bigIconPath, + (void)memcpy_s(app->appIconDir_, sizeof(app->appIconDir_), pBundleInfos[j].bigIconPath, strlen(pBundleInfos[j].bigIconPath)); app->appIconDir_[strlen(pBundleInfos[j].bigIconPath)] = 0; } diff --git a/launcher/launcher/src/main/cpp/swipe_view.h b/launcher/launcher/src/main/cpp/swipe_view.h index 4b100ca..6034ae8 100755 --- a/launcher/launcher/src/main/cpp/swipe_view.h +++ b/launcher/launcher/src/main/cpp/swipe_view.h @@ -56,7 +56,9 @@ public: virtual void OnSwipe(UISwipeView& view) override { char buf[TMP_BUF_SIZE] = { 0 }; - sprintf_s(buf, sizeof(buf), ".%d.", swipe_->GetCurrentPage() + 1); + if (sprintf_s(buf, sizeof(buf), ".%d.", swipe_->GetCurrentPage() + 1) < 0) { + return; + } lable_->SetText(buf); view_->RemoveLview(); } diff --git a/launcher/launcher/src/main/cpp/time_weather_view.cpp b/launcher/launcher/src/main/cpp/time_weather_view.cpp index d5b7b5e..b63619a 100755 --- a/launcher/launcher/src/main/cpp/time_weather_view.cpp +++ b/launcher/launcher/src/main/cpp/time_weather_view.cpp @@ -33,10 +33,7 @@ TimeWeatherView::TimeWeatherView(UIViewGroup* viewGroup) { viewGroup_ = viewGroup; } -TimeWeatherView::~TimeWeatherView() -{ - // todo other release -} +TimeWeatherView::~TimeWeatherView() {} void TimeWeatherView::SetStyle(Style sty) { diff --git a/setting/setting/src/main/cpp/app_ability_slice.cpp b/setting/setting/src/main/cpp/app_ability_slice.cpp index e5873ed..da1c662 100755 --- a/setting/setting/src/main/cpp/app_ability_slice.cpp +++ b/setting/setting/src/main/cpp/app_ability_slice.cpp @@ -144,7 +144,6 @@ void AppAbilitySlice::SetAnAppInfo(const int count, BundleInfo& pBundleInfo) itemView->Add(imageView); } - void AppAbilitySlice::SetScrollView() { scrollView_ = new UIScrollView(); diff --git a/setting/setting/src/main/cpp/app_info_ability_slice.cpp b/setting/setting/src/main/cpp/app_info_ability_slice.cpp index 16c34ad..947292a 100755 --- a/setting/setting/src/main/cpp/app_info_ability_slice.cpp +++ b/setting/setting/src/main/cpp/app_info_ability_slice.cpp @@ -70,10 +70,10 @@ void AppInfoAbilitySlice::SetHead() imageView->SetPosition(DE_HEAD_IMAGE_X, DE_HEAD_IMAGE_Y, DE_HEAD_IMAGE_WIDTH, DE_HEAD_IMAGE_HEIGHT); imageView->SetSrc(DE_IMAGE_BACK); - printf("[LOG] bundleName_-> %s +11->%s \n", bundleName_, bundleName_ + 11); // 11 + printf("[LOG] bundleName_-> %s +11->%s \n", bundleName_, bundleName_ + 11); // 11:jump behind bundleName UILabel* lablelFont = new UILabel(); lablelFont->SetPosition(DE_HEAD_TEXT_X, DE_HEAD_TEXT_Y, DE_HEAD_TEXT_WIDTH, DE_HEAD_TEXT_HEIGHT); - lablelFont->SetText(bundleName_ + 11); // use 11 + lablelFont->SetText(bundleName_ + 11); // 11:jump behind bundleName lablelFont->SetFont(DE_FONT_OTF, DE_HEAD_TEXT_SIZE); lablelFont->SetStyle(STYLE_TEXT_COLOR, DE_HEAD_TEXT_COLOR); headView_->Add(lablelFont); @@ -82,6 +82,9 @@ void AppInfoAbilitySlice::SetHead() void AppInfoAbilitySlice::SetAppPermissionInfo(int index, PermissionSaved& permissions) { UIViewGroup* itemView = new UIViewGroup(); + if (itemView == nullptr) { + return; + } int useX = 0; int useY = index * DE_ITEM_INTERVAL; itemView->SetPosition(useX, useY, DE_BUTTON_WIDTH, DE_BUTTON_HEIGHT); diff --git a/setting/setting/src/main/cpp/main_ability_slice.cpp b/setting/setting/src/main/cpp/main_ability_slice.cpp index d0ac823..f59d47b 100755 --- a/setting/setting/src/main/cpp/main_ability_slice.cpp +++ b/setting/setting/src/main/cpp/main_ability_slice.cpp @@ -173,7 +173,7 @@ void MainAbilitySlice::SetWifiButtonView(void) lablelFontWifi->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR); buttonView->Add(lablelFontWifi); - char buff[64] = {0}; + char buff[64] = {0}; // 64 is the longest in this sample int myX = WIFI_BUTTON_TEXT_SSID_X; int myY = WIFI_BUTTON_TEXT_SSID_Y; int ret = GetCurrentConnInfo(buff, sizeof(buff)); @@ -269,7 +269,7 @@ void MainAbilitySlice::SetAboutButtonView(void) lablelFontAbout->SetStyle(STYLE_TEXT_COLOR, DE_TITLE_TEXT_COLOR); buttonView->Add(lablelFontAbout); - char buff[62]; + char buff[62]; // 62 is the longest in this sample const char* gDV = GetDisplayVersion(); int err = sprintf_s(buff, sizeof(buff), "系统版本: %s", gDV); if (err < 0) { diff --git a/setting/setting/src/main/cpp/setting_display_ability_slice.cpp b/setting/setting/src/main/cpp/setting_display_ability_slice.cpp index 9ad7b5a..5b70ba1 100755 --- a/setting/setting/src/main/cpp/setting_display_ability_slice.cpp +++ b/setting/setting/src/main/cpp/setting_display_ability_slice.cpp @@ -22,10 +22,6 @@ namespace OHOS { REGISTER_AS(SettingDisplayAbilitySlice) -#define COM_SET_ON 0 -#define COM_SET_OFF 1 -#define COM_GET_STATUS 2 - SettingDisplayAbilitySlice::~SettingDisplayAbilitySlice() { if (toggleButtonView_) { diff --git a/setting/setting/src/main/cpp/wpa_work.c b/setting/setting/src/main/cpp/wpa_work.c index 9b23390..a3170e8 100755 --- a/setting/setting/src/main/cpp/wpa_work.c +++ b/setting/setting/src/main/cpp/wpa_work.c @@ -56,9 +56,7 @@ static void DumpString(const char *buf, int len, const char *tag) for (int i = 0; i < len; i++) { printf("%c", buf[i]); } - printf("\n"); - - printf("\n"); + printf("\n\n"); SAMPLE_INFO("%s dump end.", tag); } -- Gitee