[newlib-cygwin/main] Fix newlib/testsuite/newlib.search/hsearchtest.c compilation for 16-bit targets.
Jeff Johnston
jjohnstn@sourceware.org
Wed Jul 15 00:07:26 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6f47864214658e3bb31776eded6dfd44c3237bb6
commit 6f47864214658e3bb31776eded6dfd44c3237bb6
Author: Jan Dubiec <jdx@o2.pl>
Date: Mon Jul 13 03:10:28 2026 +0200
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>
Diff:
---
newlib/testsuite/newlib.search/hsearchtest.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/newlib/testsuite/newlib.search/hsearchtest.c b/newlib/testsuite/newlib.search/hsearchtest.c
index 515440382..418b0c5d6 100644
--- a/newlib/testsuite/newlib.search/hsearchtest.c
+++ b/newlib/testsuite/newlib.search/hsearchtest.c
@@ -46,6 +46,14 @@ __COPYRIGHT(
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
+
+#ifdef __INTPTR_TYPE__
+ #define INTPTRTYPE intptr_t
+#else
+ /* Just in case there is no intptr_t on a target... */
+ #define INTPTRTYPE long
+#endif
#define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e))
@@ -77,11 +85,11 @@ main(int argc, char *argv[])
ch[0] = 'a' + i;
e.key = strdup(ch); /* ptr to provided key is kept! */
TEST(e.key != NULL);
- e.data = (void *)(long)i;
+ e.data = (void *)(INTPTRTYPE)i;
ep = hsearch(e, ENTER);
TEST(ep != NULL);
TEST(strcmp(ep->key, ch) == 0);
- TEST((long)ep->data == i);
+ TEST((INTPTRTYPE)ep->data == i);
}
/* e.key should be constant from here on down. */
@@ -93,16 +101,16 @@ main(int argc, char *argv[])
ep = hsearch(e, FIND);
TEST(ep != NULL);
TEST(strcmp(ep->key, ch) == 0);
- TEST((long)ep->data == i);
+ TEST((INTPTRTYPE)ep->data == i);
}
/* Check duplicate entry. Should _not_ overwrite existing data. */
ch[0] = 'a';
- e.data = (void *)(long)12345;
+ e.data = (void *)(INTPTRTYPE)12345;
ep = hsearch(e, FIND);
TEST(ep != NULL);
TEST(strcmp(ep->key, ch) == 0);
- TEST((long)ep->data == 0);
+ TEST((INTPTRTYPE)ep->data == 0);
/* Check for something that's not there. */
ch[0] = 'A';
@@ -115,9 +123,9 @@ main(int argc, char *argv[])
ch[0] = 'b';
ep2 = hsearch(e, FIND);
TEST(ep != NULL);
- TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0);
+ TEST(strcmp(ep->key, "a") == 0 && (INTPTRTYPE)ep->data == 0);
TEST(ep2 != NULL);
- TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1);
+ TEST(strcmp(ep2->key, "b") == 0 && (INTPTRTYPE)ep2->data == 1);
hdestroy();
More information about the Newlib-cvs
mailing list