Fixed Segfault #9

This commit is contained in:
2017-08-29 19:10:08 +02:00
parent 6e12923557
commit 93dd54ab6d
2 changed files with 6 additions and 5 deletions

View File

@@ -82,10 +82,11 @@ int getRestSensor(sensor *sensor) {
//The ID is stored in the JSON root
cJSON *id = cJSON_GetObjectItemCaseSensitive(jsondata, "id");
sensor->temperature = (float)temperature->valuedouble;
sensor->humidity = (float)humidity->valuedouble;
sensor->node_id = atoi(id->valuestring);
if (temperature != NULL && humidity != NULL && id != NULL) {
sensor->temperature = (float)temperature->valuedouble;
sensor->humidity = (float)humidity->valuedouble;
sensor->node_id = atoi(id->valuestring);
}
//free
cJSON_Delete(jsondata);
free(data);