input: improve robustness, avoid NULL dereference in sr_input_send()

Applications might pass NULL for the buffer, and input modules might
accept it (or just cope). Eliminate a potential NULL dereference in
the emission of diagnostics messages.
This commit is contained in:
Gerhard Sittig 2018-06-04 23:21:01 +02:00 committed by Uwe Hermann
parent b736fa0c7d
commit 0da8e0bd2b
1 changed files with 4 additions and 2 deletions

View File

@ -582,8 +582,10 @@ SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in)
*/
SR_API int sr_input_send(const struct sr_input *in, GString *buf)
{
sr_spew("Sending %" G_GSIZE_FORMAT " bytes to %s module.",
buf->len, in->module->id);
size_t len;
len = buf ? buf->len : 0;
sr_spew("Sending %zu bytes to %s module.", len, in->module->id);
return in->module->receive((struct sr_input *)in, buf);
}