X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fasix-sigma%2Fasix-sigma.c;h=6e7f1fd716d52c04fd8c816348cb3088d2629e97;hb=e8686e3ae36c1;hp=957b1d1ac7c7a2098a979be701006fdf392dd80f;hpb=682fb08c88af64181a56c2db14ca3cef323c3ead;p=libsigrok.git diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index 957b1d1a..6e7f1fd7 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -130,13 +130,23 @@ static int sigma_write(void *buf, size_t size, struct dev_context *devc) return ret; } +/* + * NOTE: We chose the buffer size to be large enough to hold any write to the + * device. We still print a message just in case. + */ static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len, struct dev_context *devc) { size_t i; - uint8_t buf[len + 2]; + uint8_t buf[80]; int idx = 0; + if ((len + 2) > sizeof(buf)) { + sr_err("Attempted to write %zu bytes, but buffer is too small.", + len + 2); + return SR_ERR_BUG; + } + buf[idx++] = REG_ADDR_LOW | (reg & 0xf); buf[idx++] = REG_ADDR_HIGH | (reg >> 4);