summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-02-13 18:32:48 +0000
committerKaz Kylheku <kaz@kylheku.com>2025-02-13 18:32:48 +0000
commita3ff9557c6dfa6477d979028e716b331ad6ff2d7 (patch)
tree5322af773bec1823c679d1303e4126322dac18dc
parent6cfe15d64022abd9c85d3ca4e72b8e795b720212 (diff)
downloadtxr-a3ff9557c6dfa6477d979028e716b331ad6ff2d7.tar.gz
txr-a3ff9557c6dfa6477d979028e716b331ad6ff2d7.tar.bz2
txr-a3ff9557c6dfa6477d979028e716b331ad6ff2d7.zip
ffi: big endian: broken int8 and uint8 return values.
* ffi.c (ffi_i8_rput, ffi_i8_rget, ffi_u8_rput, ffi_u8_rget): These functions are not doing the correct job; they are just casting the pointer to the target type, like on little endian. The big endian rget must fetch the entire 64 bit word (ffi_arg) and convert its value to the target type. If it's a character value, the actual bits are found at *(src + 7) not at *src. The rput function must do the reverse; convert the value to the 64 bit ffi_arg and store that.
-rw-r--r--ffi.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/ffi.c b/ffi.c
index 9d72a61e..d5769e21 100644
--- a/ffi.c
+++ b/ffi.c
@@ -1885,14 +1885,15 @@ static void ffi_i8_rput(struct txr_ffi_type *tft, val n, mem_t *dst, val self)
{
i8_t v = c_i8(n, self);
(void) tft;
- *coerce(i8_t *, dst) = v;
+ *coerce(ffi_arg *, dst) = v;
}
static val ffi_i8_rget(struct txr_ffi_type *tft, mem_t *src, val self)
{
+ i8_t n = *coerce(ffi_arg *, src);
(void) tft;
(void) self;
- return num_fast(*src);
+ return num_fast(n);
}
static void ffi_u8_rput(struct txr_ffi_type *tft, val n, mem_t *dst, val self)
@@ -1900,14 +1901,15 @@ static void ffi_u8_rput(struct txr_ffi_type *tft, val n, mem_t *dst, val self)
u8_t v = c_u8(n, self);
(void) tft;
(void) self;
- *coerce(u8_t *, dst) = v;
+ *coerce(ffi_arg *, dst) = v;
}
static val ffi_u8_rget(struct txr_ffi_type *tft, mem_t *src, val self)
{
+ u8_t n = *coerce(ffi_arg *, src);
(void) tft;
(void) self;
- return num_fast(*coerce(u8_t *, src));
+ return num_fast(n);
}
#if HAVE_I16