diff mbox

Fix test-wcsncmp BUS errors.

Message ID 20150721.143904.2006742147973414532.davem@davemloft.net
State New
Headers show

Commit Message

David Miller July 21, 2015, 9:39 p.m. UTC
As currently coded, the strncmp tests dereference unaligned pointers
when setting up the test patterns.  This results in SIGBUS errors
on Sparc, for example.

Force the alignment arguments to be aligned properly for the character
type being tested.

Ok to commit?

2015-07-21  David S. Miller  <davem@davemloft.net>

	* string/test-strncmp.c (do_test_limit): Align align1 and align2
	to CHARBYTES.
	(do_test): Likewise.

Comments

David Miller July 23, 2015, 7:14 a.m. UTC | #1
From: David Miller <davem@davemloft.net>
Date: Tue, 21 Jul 2015 14:39:04 -0700 (PDT)

> As currently coded, the strncmp tests dereference unaligned pointers
> when setting up the test patterns.  This results in SIGBUS errors
> on Sparc, for example.
> 
> Force the alignment arguments to be aligned properly for the character
> type being tested.
> 
> Ok to commit?

Ping?

> 2015-07-21  David S. Miller  <davem@davemloft.net>
> 
> 	* string/test-strncmp.c (do_test_limit): Align align1 and align2
> 	to CHARBYTES.
> 	(do_test): Likewise.
> 
> diff --git a/string/test-strncmp.c b/string/test-strncmp.c
> index fb57a9b..277eb2c 100644
> --- a/string/test-strncmp.c
> +++ b/string/test-strncmp.c
> @@ -156,6 +156,9 @@ do_test_limit (size_t align1, size_t align2, size_t len, size_t n, int max_char,
>    size_t i, align_n;
>    CHAR *s1, *s2;
>  
> +  align1 &= ~(CHARBYTES - 1);
> +  align2 &= ~(CHARBYTES - 1);
> +
>    if (n == 0)
>      {
>        s1 = (CHAR *) (buf1 + page_size);
> @@ -204,6 +207,9 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
>    size_t i;
>    CHAR *s1, *s2;
>  
> +  align1 &= ~(CHARBYTES - 1);
> +  align2 &= ~(CHARBYTES - 1);
> +
>    if (n == 0)
>      return;
>
Carlos O'Donell July 23, 2015, 5:55 p.m. UTC | #2
On 07/21/2015 05:39 PM, David Miller wrote:
> As currently coded, the strncmp tests dereference unaligned pointers
> when setting up the test patterns.  This results in SIGBUS errors
> on Sparc, for example.
> 
> Force the alignment arguments to be aligned properly for the character
> type being tested.

The test is designed to show that alignment of the strings should not
impact the result of the testing. However, I agree that the fundamental
alignment of wchar_t and char need to be preserved. The latter is easily
preserved, not so with the former.

> Ok to commit?
> 
> 2015-07-21  David S. Miller  <davem@davemloft.net>
> 
> 	* string/test-strncmp.c (do_test_limit): Align align1 and align2
> 	to CHARBYTES.
> 	(do_test): Likewise.
> 
> diff --git a/string/test-strncmp.c b/string/test-strncmp.c
> index fb57a9b..277eb2c 100644
> --- a/string/test-strncmp.c
> +++ b/string/test-strncmp.c
> @@ -156,6 +156,9 @@ do_test_limit (size_t align1, size_t align2, size_t len, size_t n, int max_char,
>    size_t i, align_n;
>    CHAR *s1, *s2;
>  
> +  align1 &= ~(CHARBYTES - 1);
> +  align2 &= ~(CHARBYTES - 1);

This would make testing any align1 or align2 below CHARBYTES moot for
wchar_t, when what we really want is alignment in *addition* to the
minimum basic alignment for the type.

Can't we shift align1 and align2 by CHARBYTES - 1 to achieve that and
apply it?

If you have to align please use #include <libc-internal.h> PTR_ALIGN_*
or ALIGN_* macros.

> +
>    if (n == 0)
>      {
>        s1 = (CHAR *) (buf1 + page_size);
> @@ -204,6 +207,9 @@ do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
>    size_t i;
>    CHAR *s1, *s2;
>  
> +  align1 &= ~(CHARBYTES - 1);
> +  align2 &= ~(CHARBYTES - 1);
> +
>    if (n == 0)
>      return;
>  
> 

Post v2 please.

Cheers,
Carlos.
diff mbox

Patch

diff --git a/string/test-strncmp.c b/string/test-strncmp.c
index fb57a9b..277eb2c 100644
--- a/string/test-strncmp.c
+++ b/string/test-strncmp.c
@@ -156,6 +156,9 @@  do_test_limit (size_t align1, size_t align2, size_t len, size_t n, int max_char,
   size_t i, align_n;
   CHAR *s1, *s2;
 
+  align1 &= ~(CHARBYTES - 1);
+  align2 &= ~(CHARBYTES - 1);
+
   if (n == 0)
     {
       s1 = (CHAR *) (buf1 + page_size);
@@ -204,6 +207,9 @@  do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char,
   size_t i;
   CHAR *s1, *s2;
 
+  align1 &= ~(CHARBYTES - 1);
+  align2 &= ~(CHARBYTES - 1);
+
   if (n == 0)
     return;