iio.c: Use MAX_SIZE var upgrading strings to 128 from 64
authorBrendan Le Foll <brendan.le.foll@intel.com>
Wed, 28 Oct 2015 11:02:45 +0000 (11:02 +0000)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Tue, 15 Dec 2015 10:42:06 +0000 (10:42 +0000)
Fix inspired by Lay's PR #342 but doesn't use magic numbers

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/iio/iio.c

index 7a00d5a..f3bb6e1 100644 (file)
@@ -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 ));