diff options
author | Carmelo Amoroso <carmelo.amoroso@st.com> | 2009-07-30 14:21:20 +0200 |
---|---|---|
committer | Carmelo Amoroso <carmelo.amoroso@st.com> | 2009-07-30 14:25:52 +0200 |
commit | f14b97ca922f6afaa0d08e737259fc436af9b665 (patch) | |
tree | 556d80ca0bcc48e9d0e42613842664cdc18038f3 /test/librt/shmtest.c | |
parent | 67b2a605330caef8e0274794edca390b942a6e26 (diff) |
test_librt: Fix shmtest.c test case
Fix wrong use of sizeof (array) to retrieve the number
of elements; it was causing accessing beyond the array's boundaries.
Below the output of the testcase showing an attempt to read beyond
the array (actually 11 elements in size).
root@amorosoc:/home/carmelo# ./shmtest
Compare memory error : Offset 11, local 4262624, shm 224
Compare memory error : Offset 12, local 693493828, shm 68
Compare memory error : Offset 13, local 693489168, shm 16
Compare memory error : Offset 14, local 693826444, shm 20
.....
Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'test/librt/shmtest.c')
-rw-r--r-- | test/librt/shmtest.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/test/librt/shmtest.c b/test/librt/shmtest.c index 8f40047be..a14302d09 100644 --- a/test/librt/shmtest.c +++ b/test/librt/shmtest.c @@ -14,6 +14,8 @@ #include <sys/stat.h> #include <sys/wait.h> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + char shared_name[] = "/sharetest"; int test_data[11] = {0,1,2,3,4,5,6,7,8,9,10}; @@ -47,9 +49,9 @@ int main(void) { } else { ptest_data = mmap(0, sizeof(test_data), PROT_READ + PROT_WRITE, MAP_SHARED, fd, 0); if (ptest_data != MAP_FAILED) { - for (i=0; i < sizeof(test_data); i++) { + for (i=0; i < ARRAY_SIZE(test_data); i++) { if (ptest_data[i] != test_data[i]) { - printf("%-40s: Offset %d, local %d, shm %d", "Compare memory error", i, test_data[i], ptest_data[i]); + printf("%-40s: Offset %d, local %d, shm %d\n", "Compare memory error", i, test_data[i], ptest_data[i]); test_data_fails++; } } @@ -83,7 +85,7 @@ int main(void) { } return 0; } - for (i=0; i <sizeof(test_data); i++) + for (i=0; i < ARRAY_SIZE(test_data); i++) ptest_data[i] = test_data[i]; /* signal child */ |