summaryrefslogtreecommitdiff
path: root/libmisc/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libmisc/tests')
-rw-r--r--libmisc/tests/test_obj_nest.c12
-rw-r--r--libmisc/tests/test_rand.c6
2 files changed, 13 insertions, 5 deletions
diff --git a/libmisc/tests/test_obj_nest.c b/libmisc/tests/test_obj_nest.c
index bb9d6de..be303f2 100644
--- a/libmisc/tests/test_obj_nest.c
+++ b/libmisc/tests/test_obj_nest.c
@@ -5,6 +5,10 @@
*/
#include <string.h> /* for memcpy() */
+#include <limits.h> /* for SSIZE_MAX, not set by newlib */
+#ifndef SSIZE_MAX
+#define SSIZE_MAX (SIZE_MAX >> 1)
+#endif
#include <libmisc/obj.h>
@@ -45,8 +49,10 @@ static ssize_t myclass_read(struct myclass *self, void *buf, size_t count) {
test_assert(self);
if (count > self->len)
count = self->len;
+ if (count > SSIZE_MAX)
+ count = SSIZE_MAX;
memcpy(buf, self->buf, count);
- return count;
+ return (ssize_t)count;
}
static ssize_t myclass_write(struct myclass *self, void *buf, size_t count) {
@@ -55,9 +61,11 @@ static ssize_t myclass_write(struct myclass *self, void *buf, size_t count) {
return -1;
if (count > sizeof(self->buf))
count = sizeof(self->buf);
+ if (count > SSIZE_MAX)
+ count = SSIZE_MAX;
memcpy(self->buf, buf, count);
self->len = count;
- return count;
+ return (ssize_t)count;
}
/* main test body *************************************************************/
diff --git a/libmisc/tests/test_rand.c b/libmisc/tests/test_rand.c
index 02f4c1c..b98dacf 100644
--- a/libmisc/tests/test_rand.c
+++ b/libmisc/tests/test_rand.c
@@ -53,14 +53,14 @@ static void test_n(uint64_t cnt) {
bool seen[MAX_SEE_ALL] = {0};
for (int i = 0; i < ROUNDS; i++) {
uint64_t val = rand_uint63n(cnt);
- sum += val;
+ sum += (double)val;
test_assert(val < cnt);
if (cnt < MAX_SEE_ALL)
seen[val] = true;
}
if (cnt > 1) {
- test_assert(sum/ROUNDS > 0.45*(cnt-1));
- test_assert(sum/ROUNDS < 0.55*(cnt-1));
+ test_assert(sum/ROUNDS > 0.45*(double)(cnt-1));
+ test_assert(sum/ROUNDS < 0.55*(double)(cnt-1));
}
if (cnt < MAX_SEE_ALL) {
for (uint64_t i = 0; i < cnt; i++)