lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
* [PATCH babeltrace 1/1] Fix: test_bitfield: extend coverage by removing off-by-one in bound check
@ 2019-05-29 19:06 Mathieu Desnoyers
  0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Desnoyers @ 2019-05-29 19:06 UTC (permalink / raw)
  To: jgalar; +Cc: lttng-dev

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I4fbf927d4b2ff1c8b68b05c7843298c64b68f5a4
---
 tests/lib/test_bitfield.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tests/lib/test_bitfield.c b/tests/lib/test_bitfield.c
index bc61e118..5188335b 100644
--- a/tests/lib/test_bitfield.c
+++ b/tests/lib/test_bitfield.c
@@ -161,11 +161,12 @@ void run_test_unsigned_write(unsigned int src_ui, unsigned long long src_ull)
 	unsigned long long readval;
 	unsigned int s, l;
 
+	/* The number of bits needed to represent 0 is 0. */
 	nrbits_ui = fls_u32(src_ui);
 
 	/* Write from unsigned integer src input. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_ui; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0xFF);
 			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
 			bt_bitfield_read(target.c, unsigned char, s, l, &readval);
@@ -209,11 +210,12 @@ void run_test_unsigned_write(unsigned int src_ui, unsigned long long src_ull)
 	}
 	pass(UNSIGNED_INT_WRITE_TEST_DESC_FMT_STR, src_ui);
 
+	/* The number of bits needed to represent 0 is 0. */
 	nrbits_ull = fls_u64(src_ull);
 
 	/* Write from unsigned long long src input. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_ull; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0xFF);
 			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
 			bt_bitfield_read(target.c, unsigned char, s, l, &readval);
@@ -271,11 +273,12 @@ void run_test_unsigned_read(unsigned int src_ui, unsigned long long src_ull)
 	unsigned long long readval_ull;
 	unsigned int s, l;
 
+	/* The number of bits needed to represent 0 is 0. */
 	nrbits_ui = fls_u32(src_ui);
 
 	/* Read to unsigned integer readval output. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_ui; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0xFF);
 			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
 			bt_bitfield_read(target.c, unsigned char, s, l, &readval_ui);
@@ -319,11 +322,12 @@ void run_test_unsigned_read(unsigned int src_ui, unsigned long long src_ull)
 	}
 	pass(UNSIGNED_INT_READ_TEST_DESC_FMT_STR, src_ui);
 
+	/* The number of bits needed to represent 0 is 0. */
 	nrbits_ull = fls_u64(src_ull);
 
 	/* Read to unsigned long long readval output. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_ull; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0xFF);
 			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
 			bt_bitfield_read(target.c, unsigned char, s, l, &readval_ull);
@@ -394,7 +398,7 @@ void run_test_signed_write(int src_i, long long src_ll)
 
 	/* Write from signed integer src input. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_i; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_i; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0x0);
 			bt_bitfield_write(target.c, signed char, s, l, src_i);
 			bt_bitfield_read(target.c, signed char, s, l, &readval);
@@ -445,7 +449,7 @@ void run_test_signed_write(int src_i, long long src_ll)
 
 	/* Write from signed long long src input. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_ll; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_ll; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0x0);
 			bt_bitfield_write(target.c, signed char, s, l, src_ll);
 			bt_bitfield_read(target.c, signed char, s, l, &readval);
@@ -510,7 +514,7 @@ void run_test_signed_read(int src_i, long long src_ll)
 
 	/* Read to signed integer readval output. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_i; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_i; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0xFF);
 			bt_bitfield_write(target.c, signed char, s, l, src_i);
 			bt_bitfield_read(target.c, signed char, s, l, &readval_i);
@@ -561,7 +565,7 @@ void run_test_signed_read(int src_i, long long src_ll)
 
 	/* Read to signed long long readval output. */
 	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
-		for (l = nrbits_ll; l < (CHAR_BIT * TEST_LEN) - s; l++) {
+		for (l = nrbits_ll; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
 			init_byte_array(target.c, TEST_LEN, 0xFF);
 			bt_bitfield_write(target.c, signed char, s, l, src_ll);
 			bt_bitfield_read(target.c, signed char, s, l, &readval_ll);
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH babeltrace 1/1] Fix: test_bitfield: extend coverage by removing off-by-one in bound check
       [not found] <20190529190659.23235-1-mathieu.desnoyers@efficios.com>
@ 2019-05-29 20:57 ` Jérémie Galarneau
  0 siblings, 0 replies; 2+ messages in thread
From: Jérémie Galarneau @ 2019-05-29 20:57 UTC (permalink / raw)
  To: Mathieu Desnoyers; +Cc: lttng-dev, jgalar

Merged in master and stable-2.0.

Thanks!
Jérémie

On Wed, May 29, 2019 at 03:06:59PM -0400, Mathieu Desnoyers wrote:
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Change-Id: I4fbf927d4b2ff1c8b68b05c7843298c64b68f5a4
> ---
>  tests/lib/test_bitfield.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/tests/lib/test_bitfield.c b/tests/lib/test_bitfield.c
> index bc61e118..5188335b 100644
> --- a/tests/lib/test_bitfield.c
> +++ b/tests/lib/test_bitfield.c
> @@ -161,11 +161,12 @@ void run_test_unsigned_write(unsigned int src_ui, unsigned long long src_ull)
>  	unsigned long long readval;
>  	unsigned int s, l;
>  
> +	/* The number of bits needed to represent 0 is 0. */
>  	nrbits_ui = fls_u32(src_ui);
>  
>  	/* Write from unsigned integer src input. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_ui; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0xFF);
>  			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
>  			bt_bitfield_read(target.c, unsigned char, s, l, &readval);
> @@ -209,11 +210,12 @@ void run_test_unsigned_write(unsigned int src_ui, unsigned long long src_ull)
>  	}
>  	pass(UNSIGNED_INT_WRITE_TEST_DESC_FMT_STR, src_ui);
>  
> +	/* The number of bits needed to represent 0 is 0. */
>  	nrbits_ull = fls_u64(src_ull);
>  
>  	/* Write from unsigned long long src input. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_ull; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0xFF);
>  			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
>  			bt_bitfield_read(target.c, unsigned char, s, l, &readval);
> @@ -271,11 +273,12 @@ void run_test_unsigned_read(unsigned int src_ui, unsigned long long src_ull)
>  	unsigned long long readval_ull;
>  	unsigned int s, l;
>  
> +	/* The number of bits needed to represent 0 is 0. */
>  	nrbits_ui = fls_u32(src_ui);
>  
>  	/* Read to unsigned integer readval output. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_ui; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_ui; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0xFF);
>  			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
>  			bt_bitfield_read(target.c, unsigned char, s, l, &readval_ui);
> @@ -319,11 +322,12 @@ void run_test_unsigned_read(unsigned int src_ui, unsigned long long src_ull)
>  	}
>  	pass(UNSIGNED_INT_READ_TEST_DESC_FMT_STR, src_ui);
>  
> +	/* The number of bits needed to represent 0 is 0. */
>  	nrbits_ull = fls_u64(src_ull);
>  
>  	/* Read to unsigned long long readval output. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_ull; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_ull; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0xFF);
>  			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
>  			bt_bitfield_read(target.c, unsigned char, s, l, &readval_ull);
> @@ -394,7 +398,7 @@ void run_test_signed_write(int src_i, long long src_ll)
>  
>  	/* Write from signed integer src input. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_i; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_i; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0x0);
>  			bt_bitfield_write(target.c, signed char, s, l, src_i);
>  			bt_bitfield_read(target.c, signed char, s, l, &readval);
> @@ -445,7 +449,7 @@ void run_test_signed_write(int src_i, long long src_ll)
>  
>  	/* Write from signed long long src input. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_ll; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_ll; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0x0);
>  			bt_bitfield_write(target.c, signed char, s, l, src_ll);
>  			bt_bitfield_read(target.c, signed char, s, l, &readval);
> @@ -510,7 +514,7 @@ void run_test_signed_read(int src_i, long long src_ll)
>  
>  	/* Read to signed integer readval output. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_i; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_i; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0xFF);
>  			bt_bitfield_write(target.c, signed char, s, l, src_i);
>  			bt_bitfield_read(target.c, signed char, s, l, &readval_i);
> @@ -561,7 +565,7 @@ void run_test_signed_read(int src_i, long long src_ll)
>  
>  	/* Read to signed long long readval output. */
>  	for (s = 0; s < CHAR_BIT * TEST_LEN; s++) {
> -		for (l = nrbits_ll; l < (CHAR_BIT * TEST_LEN) - s; l++) {
> +		for (l = nrbits_ll; l <= (CHAR_BIT * TEST_LEN) - s; l++) {
>  			init_byte_array(target.c, TEST_LEN, 0xFF);
>  			bt_bitfield_write(target.c, signed char, s, l, src_ll);
>  			bt_bitfield_read(target.c, signed char, s, l, &readval_ll);
> -- 
> 2.11.0
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-29 20:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-29 19:06 [PATCH babeltrace 1/1] Fix: test_bitfield: extend coverage by removing off-by-one in bound check Mathieu Desnoyers
     [not found] <20190529190659.23235-1-mathieu.desnoyers@efficios.com>
2019-05-29 20:57 ` Jérémie Galarneau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).