Wifi-sethostspotconfig参数为null,返回成功问题

Signed-off-by: lijianhua38 <lijianhua38@huawei.com>
This commit is contained in:
lijianhua38 2023-06-14 16:19:17 +08:00
parent 71e7c1c0f9
commit fab1f95f44
2 changed files with 10 additions and 6 deletions

View File

@ -129,7 +129,9 @@ static bool GetHotspotconfigFromJs(const napi_env& env, const napi_value& object
config.SetChannel(AP_CHANNEL_5G_DEFAULT); config.SetChannel(AP_CHANNEL_5G_DEFAULT);
} }
value = 0; value = 0;
JsObjectToString(env, object, "preSharedKey", NAPI_MAX_STR_LENT, str); // 64: max length if (!JsObjectToString(env, object, "preSharedKey", NAPI_MAX_STR_LENT, str)) { // 64: max length
return false;
}
ClearJsLastException(env); ClearJsLastException(env);
config.SetPreSharedKey(str); config.SetPreSharedKey(str);
JsObjectToInt(env, object, "maxConn", value); JsObjectToInt(env, object, "maxConn", value);

View File

@ -68,14 +68,17 @@ napi_value JsObjectToString(const napi_env& env, const napi_value& object,
napi_get_named_property(env, object, fieldStr, &field); napi_get_named_property(env, object, fieldStr, &field);
NAPI_CALL(env, napi_typeof(env, field, &valueType)); NAPI_CALL(env, napi_typeof(env, field, &valueType));
NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. String expected."); if (valueType != napi_string) {
WIFI_LOGE("Wrong argument type. String expected.");
return NULL;
}
if (bufLen <= 0) { if (bufLen <= 0) {
goto error; return NULL;
} }
char *buf = (char *)malloc(bufLen); char *buf = (char *)malloc(bufLen);
if (buf == nullptr) { if (buf == nullptr) {
WIFI_LOGE("Js object to str malloc failed"); WIFI_LOGE("Js object to str malloc failed");
goto error; return NULL;
} }
(void)memset_s(buf, bufLen, 0, bufLen); (void)memset_s(buf, bufLen, 0, bufLen);
size_t result = 0; size_t result = 0;
@ -90,9 +93,8 @@ napi_value JsObjectToString(const napi_env& env, const napi_value& object,
buf = nullptr; buf = nullptr;
} else { } else {
WIFI_LOGW("Js obj to str no property: %{public}s", fieldStr); WIFI_LOGW("Js obj to str no property: %{public}s", fieldStr);
return NULL;
} }
error:
return UndefinedNapiValue(env); return UndefinedNapiValue(env);
} }