Fix network communication on arm64
authorAlexander Simon <an.alexsimon@googlemail.com>
Wed, 7 Aug 2019 11:39:18 +0000 (13:39 +0200)
committerAlexander Simon <an.alexsimon@googlemail.com>
Wed, 7 Aug 2019 11:39:18 +0000 (13:39 +0200)
Base messages consist of four uint32 integers.
Wrongly, integers are declared as a four-element uintptr_t array.
The 16 bytes are written directly by recv().
This works great for arm32, but on arm64 uintptr_t is 64 bit (8 bytes).

This patch reads four 32-bit integers and writes them into the uintptr_t
array.

pigpio.c

index 6dba0d8cf7c1d6e46542bb8bfd3b828d45cc6958..d78afd62209f1d878c97aef0805c1c49c20e9f46 100644 (file)
--- a/pigpio.c
+++ b/pigpio.c
@@ -6953,6 +6953,7 @@ static void *pthSocketThreadHandler(void *fdC)
 {
    int sock = *(int*)fdC;
    uintptr_t p[10];
+   uint32_t tmp;
    int opt;
    char buf[CMD_MAX_EXTENSION];
 
@@ -6964,7 +6965,21 @@ static void *pthSocketThreadHandler(void *fdC)
 
    while (1)
    {
-      if (recv(sock, p, 16, MSG_WAITALL) != 16) break;
+      if (sizeof(uintptr_t) == 8)
+      {
+         if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break;
+         p[0] = (uintptr_t)tmp;
+         if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break;
+         p[1] = (uintptr_t)tmp;
+         if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break;
+         p[2] = (uintptr_t)tmp;
+         if (recv(sock, &tmp, 4, MSG_WAITALL) != 4) break;
+         p[3] = (uintptr_t)tmp;
+      }
+      else
+      {
+         if (recv(sock, p, 16, MSG_WAITALL) != 16) break;
+      }
 
       if (p[3])
       {