mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-08 16:52:13 +08:00
Fix mosquitto_sub JSON printing with empty payloads.
This commit is contained in:
parent
4472c1f441
commit
5b4e4f047b
@ -313,7 +313,11 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
|
|||||||
|
|
||||||
/* Payload */
|
/* Payload */
|
||||||
if(escaped){
|
if(escaped){
|
||||||
tmp = cJSON_CreateString(message->payload);
|
if(message->payload){
|
||||||
|
tmp = cJSON_CreateString(message->payload);
|
||||||
|
}else{
|
||||||
|
tmp = cJSON_CreateNull();
|
||||||
|
}
|
||||||
if(tmp == NULL){
|
if(tmp == NULL){
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
return MOSQ_ERR_NOMEM;
|
return MOSQ_ERR_NOMEM;
|
||||||
@ -321,10 +325,18 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p
|
|||||||
cJSON_AddItemToObject(root, "payload", tmp);
|
cJSON_AddItemToObject(root, "payload", tmp);
|
||||||
}else{
|
}else{
|
||||||
return_parse_end = NULL;
|
return_parse_end = NULL;
|
||||||
tmp = cJSON_ParseWithOpts(message->payload, &return_parse_end, true);
|
if(message->payload){
|
||||||
if(tmp == NULL || return_parse_end != message->payload + message->payloadlen){
|
tmp = cJSON_ParseWithOpts(message->payload, &return_parse_end, true);
|
||||||
cJSON_Delete(root);
|
if(tmp == NULL || return_parse_end != message->payload + message->payloadlen){
|
||||||
return MOSQ_ERR_INVAL;
|
cJSON_Delete(root);
|
||||||
|
return MOSQ_ERR_INVAL;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
tmp = cJSON_CreateNull();
|
||||||
|
if(tmp == NULL){
|
||||||
|
cJSON_Delete(root);
|
||||||
|
return MOSQ_ERR_INVAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cJSON_AddItemToObject(root, "payload", tmp);
|
cJSON_AddItemToObject(root, "payload", tmp);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user