From 97b9fa090c54f6feab54bde272df374a13c0c84d Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Thu, 3 Nov 2011 10:51:27 +0100 Subject: [PATCH] Use the ARRAY_LENGTH() macro when possible This patch has been generated by the following Coccinelle semantic patch: // Use the ARRAY_LENGTH() macro when possible // // Replace open-coded array length computations with the // ARRAY_LENGTH() macro @@ type T; T[] E; @@ - (sizeof(E)/sizeof(T)) + ARRAY_LENGTH (E) --- test/blitters-test.c | 2 +- test/fetch-test.c | 2 +- test/gradient-crash-test.c | 6 +++--- test/lowlevel-blt-bench.c | 2 +- test/oob-test.c | 2 +- test/trap-crasher.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/blitters-test.c b/test/blitters-test.c index 6355632..55b6c73 100644 --- a/test/blitters-test.c +++ b/test/blitters-test.c @@ -280,7 +280,7 @@ test_composite (int testnum, int verbose) lcg_srand (testnum); - op = op_list[lcg_rand_n (sizeof (op_list) / sizeof (op_list[0]))]; + op = op_list[lcg_rand_n (ARRAY_LENGTH (op_list))]; if (lcg_rand_n (8)) { diff --git a/test/fetch-test.c b/test/fetch-test.c index fa79ad7..04e8cc5 100644 --- a/test/fetch-test.c +++ b/test/fetch-test.c @@ -103,7 +103,7 @@ static testcase_t testcases[] = }, }; -int n_test_cases = sizeof(testcases)/sizeof(testcases[0]); +int n_test_cases = ARRAY_LENGTH (testcases); static uint32_t diff --git a/test/gradient-crash-test.c b/test/gradient-crash-test.c index c85712d..73e5bbc 100644 --- a/test/gradient-crash-test.c +++ b/test/gradient-crash-test.c @@ -106,17 +106,17 @@ main (int argc, char **argv) if (i == 0) { stops = onestop; - num_stops = sizeof(onestop) / sizeof(onestop[0]); + num_stops = ARRAY_LENGTH (onestop); } else if (i == 1) { stops = subsetstops; - num_stops = sizeof(subsetstops) / sizeof(subsetstops[0]); + num_stops = ARRAY_LENGTH (subsetstops); } else { stops = stops01; - num_stops = sizeof(stops01) / sizeof(stops01[0]); + num_stops = ARRAY_LENGTH (stops01); } for (j = 0; j < 3; ++j) diff --git a/test/lowlevel-blt-bench.c b/test/lowlevel-blt-bench.c index 67cd939..ba7f307 100644 --- a/test/lowlevel-blt-bench.c +++ b/test/lowlevel-blt-bench.c @@ -703,7 +703,7 @@ main (int argc, char *argv[]) x / 1000000., x / 4000000); printf ("---\n"); - for (i = 0; i < sizeof(tests_tbl) / sizeof(tests_tbl[0]); i++) + for (i = 0; i < ARRAY_LENGTH (tests_tbl); i++) { if (strcmp (pattern, "all") == 0 || strstr (tests_tbl[i].testname, pattern)) { diff --git a/test/oob-test.c b/test/oob-test.c index 9c1a25d..0d19b50 100644 --- a/test/oob-test.c +++ b/test/oob-test.c @@ -94,7 +94,7 @@ main (int argc, char **argv) { int i; - for (i = 0; i < sizeof (info) / sizeof (info[0]); ++i) + for (i = 0; i < ARRAY_LENGTH (info); ++i) test_composite (&info[i]); return 0; diff --git a/test/trap-crasher.c b/test/trap-crasher.c index db7e01a..4e4cac2 100644 --- a/test/trap-crasher.c +++ b/test/trap-crasher.c @@ -22,6 +22,6 @@ main() dst = pixman_image_create_bits (PIXMAN_a8, 1, 1, NULL, -1); - pixman_add_trapezoids (dst, 0, 0, sizeof (traps)/sizeof (traps[0]), traps); + pixman_add_trapezoids (dst, 0, 0, ARRAY_LENGTH (traps), traps); return (0); } -- 2.7.4