Skip to content

Commit 0902ced

Browse files
authored
修复param.required()==false时可能触发未定义的问题 (#705)
1 parent aef527f commit 0902ced

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

main/iot/thing.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,18 @@ void Thing::Invoke(const cJSON* command) {
6464
throw std::runtime_error("Parameter " + param.name() + " is required");
6565
}
6666
if (param.type() == kValueTypeNumber) {
67-
param.set_number(input_param->valueint);
67+
if (cJSON_IsNumber(input_param)) {
68+
param.set_number(input_param->valueint);
69+
}
6870
} else if (param.type() == kValueTypeString) {
69-
param.set_string(input_param->valuestring);
71+
if (cJSON_IsString(input_param) || cJSON_IsObject(input_param) || cJSON_IsArray(input_param)) {
72+
std::string value_str = input_param->valuestring;
73+
param.set_string(value_str);
74+
}
7075
} else if (param.type() == kValueTypeBoolean) {
71-
param.set_boolean(input_param->valueint == 1);
76+
if (cJSON_IsBool(input_param)) {
77+
param.set_boolean(input_param->valueint == 1);
78+
}
7279
}
7380
}
7481

0 commit comments

Comments
 (0)