diff options
author | David Gstir <david@sigma-star.at> | 2016-02-22 14:52:03 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2017-02-21 10:13:11 +0100 |
commit | d600419ef43dd04c0e83e4ce0fc714d2f4e5ac8c (patch) | |
tree | 5de1e3cadef2bde3526b0657b78eabc6016f12d6 /tests/ubi-tests/io_read.c | |
parent | 1710e0c53e5d3768ba7a58e26ffc8cb105d2ae62 (diff) |
ubi: tests: Replace variable-length array with malloc()
io_read and io_update of mtd-utils use variable-length arrays for test data.
Since this could result in allocating many megabytes using alloca(), switch
to malloc().
Signed-off-by: David Gstir <david@sigma-star.at>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/ubi-tests/io_read.c')
-rw-r--r-- | tests/ubi-tests/io_read.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/ubi-tests/io_read.c b/tests/ubi-tests/io_read.c index 673624f..386291e 100644 --- a/tests/ubi-tests/io_read.c +++ b/tests/ubi-tests/io_read.c @@ -161,8 +161,18 @@ remove: static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off) { int i, len1; - unsigned char ck_buf[len], buf[len]; + unsigned char *ck_buf = NULL; + unsigned char *buf = NULL; off_t new_off; + int ret = -1; + + ck_buf = malloc(len); + buf = malloc(len); + + if (!ck_buf || !buf) { + failed("malloc"); + goto out; + } if (off + len > vol_info->data_bytes) len1 = vol_info->data_bytes - off; @@ -172,12 +182,12 @@ static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off) if (lseek(fd, off, SEEK_SET) != off) { failed("seek"); errorm("len = %d", len); - return -1; + goto out; } if (read(fd, buf, len) != len1) { failed("read"); errorm("len = %d", len); - return -1; + goto out; } new_off = lseek(fd, 0, SEEK_CUR); @@ -187,7 +197,7 @@ static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off) else errorm("read %d bytes from %lld, but resulting " "offset is %lld", len1, (long long) off, (long long) new_off); - return -1; + goto out; } for (i = 0; i < len1; i++) @@ -197,10 +207,14 @@ static int test_read3(const struct ubi_vol_info *vol_info, int len, off_t off) errorm("incorrect data read from offset %lld", (long long)off); errorm("len = %d", len); - return -1; + goto out; } - return 0; + ret = 0; +out: + free(buf); + free(ck_buf); + return ret; } /* |