Skip to content

Commit 6f47864

Browse files
jdx-ghjjohnstn
authored andcommitted
Fix newlib/testsuite/newlib.search/hsearchtest.c compilation for 16-bit targets.
When the test case is compiled for a 16-bit target, the compiler emits the two warnings shown below, causing the test to fail. The code assumes that pointers are 32 bits wide, which obviously is not true. This patch fixes the issue. Signed-off-by: Jan Dubiec <jdx@o2.pl>
1 parent 5079e09 commit 6f47864

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

newlib/testsuite/newlib.search/hsearchtest.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ __COPYRIGHT(
4646
#include <stdlib.h>
4747
#include <stdio.h>
4848
#include <string.h>
49+
#include <stdint.h>
50+
51+
#ifdef __INTPTR_TYPE__
52+
#define INTPTRTYPE intptr_t
53+
#else
54+
/* Just in case there is no intptr_t on a target... */
55+
#define INTPTRTYPE long
56+
#endif
4957

5058
#define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e))
5159

@@ -77,11 +85,11 @@ main(int argc, char *argv[])
7785
ch[0] = 'a' + i;
7886
e.key = strdup(ch); /* ptr to provided key is kept! */
7987
TEST(e.key != NULL);
80-
e.data = (void *)(long)i;
88+
e.data = (void *)(INTPTRTYPE)i;
8189
ep = hsearch(e, ENTER);
8290
TEST(ep != NULL);
8391
TEST(strcmp(ep->key, ch) == 0);
84-
TEST((long)ep->data == i);
92+
TEST((INTPTRTYPE)ep->data == i);
8593
}
8694

8795
/* e.key should be constant from here on down. */
@@ -93,16 +101,16 @@ main(int argc, char *argv[])
93101
ep = hsearch(e, FIND);
94102
TEST(ep != NULL);
95103
TEST(strcmp(ep->key, ch) == 0);
96-
TEST((long)ep->data == i);
104+
TEST((INTPTRTYPE)ep->data == i);
97105
}
98106

99107
/* Check duplicate entry. Should _not_ overwrite existing data. */
100108
ch[0] = 'a';
101-
e.data = (void *)(long)12345;
109+
e.data = (void *)(INTPTRTYPE)12345;
102110
ep = hsearch(e, FIND);
103111
TEST(ep != NULL);
104112
TEST(strcmp(ep->key, ch) == 0);
105-
TEST((long)ep->data == 0);
113+
TEST((INTPTRTYPE)ep->data == 0);
106114

107115
/* Check for something that's not there. */
108116
ch[0] = 'A';
@@ -115,9 +123,9 @@ main(int argc, char *argv[])
115123
ch[0] = 'b';
116124
ep2 = hsearch(e, FIND);
117125
TEST(ep != NULL);
118-
TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0);
126+
TEST(strcmp(ep->key, "a") == 0 && (INTPTRTYPE)ep->data == 0);
119127
TEST(ep2 != NULL);
120-
TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1);
128+
TEST(strcmp(ep2->key, "b") == 0 && (INTPTRTYPE)ep2->data == 1);
121129

122130
hdestroy();
123131

0 commit comments

Comments
 (0)