From 789fceb066418cd9bc841a3549eec5c81723943d Mon Sep 17 00:00:00 2001 From: Caisking Date: Thu, 19 Mar 2026 18:27:12 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0goalmodel=E7=9A=84=E5=AE=89?= =?utf8?q?=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeapp/nativeui/goal/src/goalmodel.cpp | 104 +++++++++++++++--- 1 file changed, 88 insertions(+), 16 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/goalmodel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/goalmodel.cpp index 9eb81bbd1..4e7c0e03f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/goalmodel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/goal/src/goalmodel.cpp @@ -66,6 +66,10 @@ namespace OHOS uint8_t GoalModel::getstepvalue() { int stepgoal = step_goal; + if (stepgoal <= 0) + { + return 0; + } int stepdata = show_data_step_refresh();//cywee_get_step_data();//OHOS::ActivityModel::GetInstance()->GetStepCounter(); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %d %f ",stepdata,stepgoal,((float)stepdata/(float)stepgoal) * 100); uint8_t value = ((float)stepdata / (float)stepgoal) * 100; @@ -325,11 +329,24 @@ namespace OHOS { return 0; } + if (size == 0 || (size % 8) != 0) + { + fclose(fp); + return 0; + } uint8_t *date=(uint8_t *)malloc(size); - if(date==NULL) return 0; + if(date==NULL) { + fclose(fp); + return 0; + } - fread(date,sizeof(uint8_t),size,fp); + size_t readSize = fread(date,sizeof(uint8_t),size,fp); fclose(fp); + if (readSize != size) + { + free(date); + return 0; + } int32_t sing_date=0; int32_t timetemp=0; @@ -341,8 +358,12 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %d", sing_date); - struct tm *timeinfo; - timeinfo = localtime((time_t *) &timetemp); + time_t ts = static_cast(timetemp); + struct tm *timeinfo = localtime(&ts); + if (timeinfo == nullptr) + { + continue; + } if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) @@ -384,11 +405,24 @@ namespace OHOS { return 0; } + if (size == 0 || (size % 8) != 0) + { + fclose(fp); + return 0; + } uint8_t *date=(uint8_t *)malloc(size); - if(date==NULL) return 0; + if(date==NULL) { + fclose(fp); + return 0; + } - fread(date,sizeof(uint8_t),size,fp); + size_t readSize = fread(date,sizeof(uint8_t),size,fp); fclose(fp); + if (readSize != size) + { + free(date); + return 0; + } float sing_date=0; int32_t timetemp=0; @@ -401,8 +435,12 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %f", sing_date); - struct tm *timeinfo; - timeinfo = localtime((time_t *) &timetemp); + time_t ts = static_cast(timetemp); + struct tm *timeinfo = localtime(&ts); + if (timeinfo == nullptr) + { + continue; + } if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) @@ -445,11 +483,24 @@ namespace OHOS { return 0; } + if (size == 0 || (size % 8) != 0) + { + fclose(fp); + return 0; + } uint8_t *date=(uint8_t *)malloc(size); - if(date==NULL) return 0; + if(date==NULL) { + fclose(fp); + return 0; + } - fread(date,sizeof(uint8_t),size,fp); + size_t readSize = fread(date,sizeof(uint8_t),size,fp); fclose(fp); + if (readSize != size) + { + free(date); + return 0; + } float sing_date=0; int32_t timetemp=0; @@ -461,8 +512,12 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "data: %f", sing_date); - struct tm *timeinfo; - timeinfo = localtime((time_t *) &timetemp); + time_t ts = static_cast(timetemp); + struct tm *timeinfo = localtime(&ts); + if (timeinfo == nullptr) + { + continue; + } if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) @@ -506,11 +561,24 @@ namespace OHOS { return 0; } + if (size == 0 || (size % 6) != 0) + { + fclose(fp); + return 0; + } uint8_t *date=(uint8_t *)malloc(size); - if(date==NULL) return 0; + if(date==NULL) { + fclose(fp); + return 0; + } - fread(date,sizeof(uint8_t),size,fp); + size_t readSize = fread(date,sizeof(uint8_t),size,fp); fclose(fp); + if (readSize != size) + { + free(date); + return 0; + } uint16 sing_date=0; int32_t timetemp=0; @@ -522,8 +590,12 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d", timetemp); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data: %d", sing_date); - struct tm *timeinfo; - timeinfo = localtime((time_t *) &timetemp); + time_t ts = static_cast(timetemp); + struct tm *timeinfo = localtime(&ts); + if (timeinfo == nullptr) + { + continue; + } if(sing_date>0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) -- 2.17.1