From 069985641ec6621b52a97aa1f461cea20fcdfe61 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Wed, 28 Oct 2015 11:02:45 +0000 Subject: [PATCH] iio.c: Use MAX_SIZE var upgrading strings to 128 from 64 Fix inspired by Lay's PR #342 but doesn't use magic numbers Signed-off-by: Brendan Le Foll --- src/iio/iio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/iio/iio.c b/src/iio/iio.c index 7a00d5a..f3bb6e1 100644 --- a/src/iio/iio.c +++ b/src/iio/iio.c @@ -205,11 +205,11 @@ mraa_iio_get_device_num_by_name(const char* name) mraa_result_t mraa_iio_read(mraa_iio_context dev, const char* attr_chan, float* data) { - char buf[64]; - snprintf(buf, 64, IIO_SYSFS_DEVICE "%d/%s", dev->num, attr_chan); + char buf[MAX_SIZE]; + snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/%s", dev->num, attr_chan); int fd = open(buf, O_RDONLY); if (fd != -1) { - int len = read(fd, &buf, 64); + int len = read(fd, &buf, MAX_SIZE); *data = strtol(buf, NULL, 10); return MRAA_SUCCESS; } @@ -356,11 +356,11 @@ mraa_iio_get_event_data(mraa_iio_context dev) mraa_result_t mraa_iio_event_read(mraa_iio_context dev, const char* attribute, float* data) { - char buf[64]; - snprintf(buf, 64, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS "/%s", dev->num, attribute); + char buf[MAX_SIZE]; + snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS "/%s", dev->num, attribute); int fd = open(buf, O_RDONLY); if (fd != -1) { - int len = read(fd, &buf, 64); + int len = read(fd, &buf, MAX_SIZE); *data = strtol(buf, NULL, 10); return MRAA_SUCCESS; } @@ -371,8 +371,8 @@ mraa_result_t mraa_iio_event_write(mraa_iio_context dev, const char* attribute, const char* data) { int len; - char buf[128]; - snprintf(buf, 128, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS "/%s", dev->num, attribute); + char buf[MAX_SIZE]; + snprintf(buf, MAX_SIZE, IIO_SYSFS_DEVICE "%d/" IIO_EVENTS "/%s", dev->num, attribute); int fd = open(buf, O_WRONLY); if (fd != -1) { int len = write(fd, data, ( strlen(data) +1 )); -- 2.7.4