From 4f4f38f4f5d09cd5f5f1d036db841fb23d69e59d Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 25 Jul 2023 13:56:30 +0200 Subject: [PATCH 1/2] types: don't rely on implicit type conversion in ucv_compare() - Don't implicitly convert intptr_t difference to int8_t but perform explicit comparisons - Don't implicitly convert strcmp() int result to int8_t Fixes: #165 Signed-off-by: Jo-Philipp Wich --- types.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/types.c b/types.c index 5758f74f..d6014794 100644 --- a/types.c +++ b/types.c @@ -1998,7 +1998,7 @@ ucv_compare(int how, uc_value_t *v1, uc_value_t *v2, int *deltap) uint64_t u1, u2; int64_t n1, n2; double d1, d2; - int8_t delta; + int delta; /* at least one operand is null and we compare for equality or inequality ... */ if ((!v1 || !v2) && (how == I_EQ || how == I_NE)) { @@ -2015,7 +2015,12 @@ ucv_compare(int how, uc_value_t *v1, uc_value_t *v2, int *deltap) /* ... both operands are of the same, non-scalar type... */ if (t1 == t2 && !ucv_is_scalar(v1)) { /* ... compare memory addrs */ - delta = (intptr_t)v1 - (intptr_t)v2; + if ((uintptr_t)v1 == (uintptr_t)v2) + delta = 0; + else if ((uintptr_t)v1 < (uintptr_t)v2) + delta = -1; + else + delta = 1; } /* ... operands are of different type or at least one is scalar... */ From 093684df07cee69a06deed665bbb0cb3eeaf3841 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 25 Jul 2023 13:59:33 +0200 Subject: [PATCH 2/2] fs: explicitly compare isatty() result Reportedly, automatic conversion of the `isatty()` int result value to a bool does not work correctly on PPC. Explicitly compare the result value with `1` to infer the boolean result value. Fixes: #165 Signed-off-by: Jo-Philipp Wich --- lib/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fs.c b/lib/fs.c index 5266ce99..e00f7fac 100644 --- a/lib/fs.c +++ b/lib/fs.c @@ -838,7 +838,7 @@ uc_fs_isatty(uc_vm_t *vm, size_t nargs) if (fd == -1) err_return(errno); - return ucv_boolean_new(isatty(fd)); + return ucv_boolean_new(isatty(fd) == 1); } /**