From: Martin Buck <mbuck@debian.org>
Date: Sun, 15 Oct 2023 23:36:23 +0200
Subject: Fix filepos2z() for 32 bit big endian machines

Bug-Debian: http://bugs.debian.org/414893
Forwarded: yes

Fixes a FTBFS bug on big endian machines.

Update 2019-01-14: Still required with calc 2.12.7.2 on mips, otherwise, we
get this (on minkus.debian.org, sid chroot):

gcc  -DCALC_SRC -DCUSTOM -Wall  -g -O2 -fdebug-prefix-map=/home/mbuck/apcalc-2.12.7.2=. -fstack-protector-strong -Wformat -Werror=format-security   -O3 -g3 -Wno-error=long-long -Wno-long-long -c file.c
In file included from qmath.h:32,
                 from cmath.h:32,
                 from value.h:33,
                 from calc.h:33,
                 from file.c:39:
file.c: In function 'filepos2z':
zmath.h:85:46: error: incompatible types when assigning to type 'HALF' {aka 'long unsigned int'} from type 'FILEPOS' {aka 'struct _G_fpos_t'}
 #define SWAP_HALF_IN_B32(dest, src) (*(dest) = *(src))
                                              ^
fposval.h:15:42: note: in expansion of macro 'SWAP_HALF_IN_B32'
 #define SWAP_HALF_IN_FILEPOS(dest, src)  SWAP_HALF_IN_B32(dest, src)
                                          ^~~~~~~~~~~~~~~~
file.c:1370:2: note: in expansion of macro 'SWAP_HALF_IN_FILEPOS'
  SWAP_HALF_IN_FILEPOS(ret.v, &pos);
  ^~~~~~~~~~~~~~~~~~~~
Author: Martin Buck <mbuck@debian.org>
---
 fposval.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fposval.c b/fposval.c
index 5bb673c..da04aeb 100644
--- a/fposval.c
+++ b/fposval.c
@@ -114,15 +114,20 @@ main(int UNUSED(argc), char **argv)
 	/*
 	 * Big Endian
 	 */
+	/*
+	 * Use casts to (HALF *) because SWAP_HALF_IN_B* might expand to
+	 * a simple assignment and SWAP_HALF_IN_FILEPOS might get a
+	 * (HALF *) and a (FILEPOS *) which are not assignment-compatible.
+	 */
 	if (fileposlen == 64) {
 		printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
-		       "\tSWAP_HALF_IN_B64(dest, src)\n");
+		       "\tSWAP_HALF_IN_B64((HALF *)dest, (HALF *)src)\n");
 	} else if (fileposlen == 32) {
 		printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
-		       "\tSWAP_HALF_IN_B32(dest, src)\n");
+		       "\tSWAP_HALF_IN_B32((HALF *)dest, (HALF *)src)\n");
 	} else if (fileposlen%BASEB == 0) {
 		printf("#define SWAP_HALF_IN_FILEPOS(dest, src) \\\n"
-		       "\tswap_HALFs(dest, src, %d)\n",
+		       "\tswap_HALFs((HALF *)dest, (HALF *)src, %d)\n",
 		       fileposlen/BASEB);
 	} else {
 		fprintf(stderr, "%s: unexpected BIG_ENDIAN FILEPOS bit size: %d\n",
