mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
Use uintptr_t in string/tester for pointer alignment
The code assumed unsigned long can represent pointers. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
This commit is contained in:
@ -27,6 +27,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -529,7 +530,7 @@ test_strlen (void)
|
|||||||
char *p;
|
char *p;
|
||||||
for (i=0; i < 0x100; i++)
|
for (i=0; i < 0x100; i++)
|
||||||
{
|
{
|
||||||
p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i;
|
p = (char *) ((uintptr_t)(buf + 0xff) & ~0xff) + i;
|
||||||
strcpy (p, "OK");
|
strcpy (p, "OK");
|
||||||
strcpy (p+3, "BAD/WRONG");
|
strcpy (p+3, "BAD/WRONG");
|
||||||
check (strlen (p) == 2, 4+i);
|
check (strlen (p) == 2, 4+i);
|
||||||
@ -554,7 +555,7 @@ test_strnlen (void)
|
|||||||
char buf[4096];
|
char buf[4096];
|
||||||
for (int i = 0; i < 0x100; ++i)
|
for (int i = 0; i < 0x100; ++i)
|
||||||
{
|
{
|
||||||
char *p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i;
|
char *p = (char *) ((uintptr_t)(buf + 0xff) & ~0xff) + i;
|
||||||
strcpy (p, "OK");
|
strcpy (p, "OK");
|
||||||
strcpy (p + 3, "BAD/WRONG");
|
strcpy (p + 3, "BAD/WRONG");
|
||||||
check (strnlen (p, 100) == 2, 10 + i);
|
check (strnlen (p, 100) == 2, 10 + i);
|
||||||
@ -582,7 +583,7 @@ test_strchr (void)
|
|||||||
char *p;
|
char *p;
|
||||||
for (i=0; i < 0x100; i++)
|
for (i=0; i < 0x100; i++)
|
||||||
{
|
{
|
||||||
p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i;
|
p = (char *) ((uintptr_t) (buf + 0xff) & ~0xff) + i;
|
||||||
strcpy (p, "OK");
|
strcpy (p, "OK");
|
||||||
strcpy (p+3, "BAD/WRONG");
|
strcpy (p+3, "BAD/WRONG");
|
||||||
check (strchr (p, '/') == NULL, 9+i);
|
check (strchr (p, '/') == NULL, 9+i);
|
||||||
@ -614,7 +615,7 @@ test_strchrnul (void)
|
|||||||
char *p;
|
char *p;
|
||||||
for (i=0; i < 0x100; i++)
|
for (i=0; i < 0x100; i++)
|
||||||
{
|
{
|
||||||
p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i;
|
p = (char *) ((uintptr_t) (buf + 0xff) & ~0xff) + i;
|
||||||
strcpy (p, "OK");
|
strcpy (p, "OK");
|
||||||
strcpy (p+3, "BAD/WRONG");
|
strcpy (p+3, "BAD/WRONG");
|
||||||
cp = strchrnul (p, '/');
|
cp = strchrnul (p, '/');
|
||||||
@ -643,7 +644,7 @@ test_rawmemchr (void)
|
|||||||
char *p;
|
char *p;
|
||||||
for (i=0; i < 0x100; i++)
|
for (i=0; i < 0x100; i++)
|
||||||
{
|
{
|
||||||
p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i;
|
p = (char *) ((uintptr_t) (buf + 0xff) & ~0xff) + i;
|
||||||
strcpy (p, "OK");
|
strcpy (p, "OK");
|
||||||
strcpy (p+3, "BAD/WRONG");
|
strcpy (p+3, "BAD/WRONG");
|
||||||
check (rawmemchr (p, 'R') == p+8, 6+i);
|
check (rawmemchr (p, 'R') == p+8, 6+i);
|
||||||
@ -689,7 +690,7 @@ test_strrchr (void)
|
|||||||
char *p;
|
char *p;
|
||||||
for (i=0; i < 0x100; i++)
|
for (i=0; i < 0x100; i++)
|
||||||
{
|
{
|
||||||
p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i;
|
p = (char *) ((uintptr_t) (buf + 0xff) & ~0xff) + i;
|
||||||
strcpy (p, "OK");
|
strcpy (p, "OK");
|
||||||
strcpy (p+3, "BAD/WRONG");
|
strcpy (p+3, "BAD/WRONG");
|
||||||
check (strrchr (p, '/') == NULL, 9+i);
|
check (strrchr (p, '/') == NULL, 9+i);
|
||||||
|
Reference in New Issue
Block a user