From c1b4121e3bb3ce1c79b1e9fa199c656ad8ed0e54 Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Tue, 16 Jul 2019 18:17:49 +0000 Subject: [PATCH] dm: virtio-i2c: minor fix Change the condition of checking native adapter number. Change sprintf to snprintf. Tracked-On: #3437 Signed-off-by: Conghui Chen Reviewed-by: Yonghua Huang --- devicemodel/hw/pci/virtio/virtio_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio_i2c.c b/devicemodel/hw/pci/virtio/virtio_i2c.c index ffa7a1e44..023783e20 100644 --- a/devicemodel/hw/pci/virtio/virtio_i2c.c +++ b/devicemodel/hw/pci/virtio/virtio_i2c.c @@ -443,7 +443,7 @@ native_adapter_create(int bus, uint16_t slave_addr[], int n_slave) return NULL; } - sprintf(native_path, "/dev/i2c-%d", bus); + snprintf(native_path, sizeof(native_path), "/dev/i2c-%d", bus); fd = open(native_path, O_RDWR); if (fd < 0) { WPRINTF("virtio_i2c: failed to open %s\n", native_path); @@ -645,7 +645,7 @@ virtio_i2c_parse(struct virtio_i2c *vi2c, char *optstr) } cp = t; } - if (n_adapter > MAX_NATIVE_I2C_ADAPTER) { + if (n_adapter >= MAX_NATIVE_I2C_ADAPTER) { WPRINTF("too many adapter, only support %d \n", MAX_NATIVE_I2C_ADAPTER); return -1; }