From: Gerhard Sittig Date: Mon, 4 Jun 2018 21:21:01 +0000 (+0200) Subject: input: improve robustness, avoid NULL dereference in sr_input_send() X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0da8e0bd2bf8496745ca4796c7f533dffc920f5f;p=libsigrok.git 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. --- diff --git a/src/input/input.c b/src/input/input.c index 4d3eb985..282084ca 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -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); }