diff --git a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp index 14268ade65053798fcba149b36a07458650f8eee..ebb2d563a93adbe8135703987da3154a245f6c6e 100644 --- a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp +++ b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp @@ -150,7 +150,7 @@ static bool ParseVibratorPattern(::ohos::vibrator::VibratorPattern pattern, Vibr { CALL_LOG_ENTER; vibrateInfo.vibratorPattern.time = pattern.time; - vibrateInfo.vibratorPattern.eventNum = pattern.events.size(); + vibrateInfo.vibratorPattern.eventNum = static_cast(pattern.events.size()); if (vibrateInfo.vibratorPattern.eventNum <= 0 || vibrateInfo.vibratorPattern.eventNum > EVENT_NUM_MAX) { MISC_HILOGE("length should not be less than or equal to 0 or greater than EVENT_NUM_MAX"); return false; @@ -183,7 +183,7 @@ static void PrintVibratorPattern(::ohos::vibrator::VibratorPattern &vibratorPatt } MISC_HILOGD("PrintVibratorPattern, time:%{public}d, eventNum:%{public}u", vibratorPattern.time, vibratorPattern.events.size()); - for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { + for (int32_t i = 0; i < static_cast(vibratorPattern.events.size()); ++i) { MISC_HILOGD("PrintVibratorPattern, type:%{public}d, time:%{public}d, duration:%{public}d, \ intensity:%{public}d, frequency:%{public}d, index:%{public}d, pointNum:%{public}u", static_cast(vibratorPattern.events[i].eventType), vibratorPattern.events[i].time, @@ -195,7 +195,7 @@ static void PrintVibratorPattern(::ohos::vibrator::VibratorPattern &vibratorPatt return; } ::taihe::array<::ohos::vibrator::VibratorCurvePoint> point = vibratorPattern.events[i].points.value(); - for (int32_t j = 0; j < vibratorPattern.events[i].points.value().size(); ++j) { + for (int32_t j = 0; j < static_cast(vibratorPattern.events[i].points.value().size()); ++j) { MISC_HILOGD("PrintVibratorPattern, time:%{public}d, intensity:%{public}d, frequency:%{public}d", point[j].time, point[j].intensity.value(), point[j].frequency.value()); } @@ -210,7 +210,7 @@ static bool CheckVibratorCurvePoint(const ::ohos::vibrator::VibratorEvent &event MISC_HILOGE("The points size is out of range, pointNum:%{public}u", event.points.value().size()); return false; } - for (int32_t j = 0; j < event.points.value().size(); ++j) { + for (int32_t j = 0; j < static_cast(event.points.value().size()); ++j) { if ((event.points.value()[j].time < 0) || (event.points.value()[j].time > event.duration.value())) { MISC_HILOGE("time in points is out of range, time:%{public}d", event.points.value()[j].time); return false; @@ -277,7 +277,7 @@ static bool CheckVibratorPatternParameter(::ohos::vibrator::VibratorPattern &vib MISC_HILOGE("The event num is out of range, eventNum:%{public}u", vibratorPattern.events.size()); return false; } - for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { + for (int32_t i = 0; i < static_cast(vibratorPattern.events.size()); ++i) { if (!CheckVibratorEvent(vibratorPattern.events[i])) { MISC_HILOGE("CheckVibratorEvent failed"); return false; diff --git a/frameworks/js/ani/vibrator/src/vibrator_ani.cpp b/frameworks/js/ani/vibrator/src/vibrator_ani.cpp index 9fe86eeca849144faae056de91ff05cbcc89b2ac..bb7f3735da83d9c004178b2c690f63c8db7d8585 100644 --- a/frameworks/js/ani/vibrator/src/vibrator_ani.cpp +++ b/frameworks/js/ani/vibrator/src/vibrator_ani.cpp @@ -305,19 +305,19 @@ static bool GetPropertyAsDouble(ani_env* env, ani_object obj, const char* proper ani_boolean isUndefined = false; if (env->Object_GetPropertyByName_Ref(obj, propertyName, &propRef) != ANI_OK) { - MISC_HILOGE("GetPropertyAsDouble: Failed to get property '%{punlic}s'", propertyName); + MISC_HILOGE("GetPropertyAsDouble, failed to get property:%{public}s", propertyName); return false; } env->Reference_IsUndefined(propRef, &isUndefined); if (isUndefined) { - MISC_HILOGE("GetPropertyAsDouble: Property '%{punlic}s' is undefined", propertyName); + MISC_HILOGE("GetPropertyAsDouble, property:%{public}s is undefined", propertyName); return false; } if (env->Object_CallMethodByName_Double(static_cast(propRef), "doubleValue", nullptr, outValue) != ANI_OK) { - MISC_HILOGE("GetPropertyAsDouble: Failed to call 'doubleValue' on property '%{punlic}s'", propertyName); + MISC_HILOGE("GetPropertyAsDouble, failed to call doubleValue on property:%{public}s'", propertyName); return false; } @@ -401,7 +401,7 @@ static bool ParsePointsArray(ani_env *env, ani_object parentObject, VibratorEven return false; } - event.pointNum = static_cast(sizePoints); + event.pointNum = static_cast(sizePoints); if (static_cast(sizePoints) > 0) { if (!ParseVibratorCurvePointArray(env, static_cast(points), @@ -749,6 +749,38 @@ static bool ParseEffectTypeAndParameters(ani_env *env, ani_object effect, Vibrat return true; } +static void FreeVibrateInfo(VibrateInfo &vibrateInfo) +{ + int32_t patternSize = vibrateInfo.count; + if (patternSize <= 0) { + MISC_HILOGW("Patterns is not need to free, pattern size:%{public}d", patternSize); + return; + } + auto patterns = &vibrateInfo.vibratorPattern; + if (patterns == nullptr) { + MISC_HILOGW("Patterns is not need to free, patterns is"); + return; + } + for (int32_t i = 0; i < patternSize; ++i) { + int32_t eventNum = patterns[i].eventNum; + if ((eventNum <= 0) || (patterns[i].events == nullptr)) { + MISC_HILOGW("Events is not need to free, event size:%{public}d", eventNum); + continue; + } + auto events = patterns[i].events; + for (int32_t j = 0; j < eventNum; ++j) { + if (events[j].points != nullptr) { + free(events[j].points); + events[j].points = nullptr; + } + } + free(events); + events = nullptr; + } + free(patterns); + patterns = nullptr; +} + static void StartVibrationSync([[maybe_unused]] ani_env *env, ani_object effect, ani_object attribute) { ani_namespace ns; @@ -768,6 +800,7 @@ static void StartVibrationSync([[maybe_unused]] ani_env *env, ani_object effect, return; } if (!ParserParamFromVibrateAttribute(env, attribute, vibrateInfo)) { + FreeVibrateInfo(vibrateInfo); ThrowBusinessError(env, PARAMETER_ERROR, "ParserParamFromVibrateAttribute failed!"); return; }