canopenterm: Fix build with musl

Signed-off-by: Khem Raj <raj.khem@gmail.com>
This commit is contained in:
Khem Raj 2024-11-22 10:40:57 -08:00
parent c5aa5e0a20
commit e7be0ede42
No known key found for this signature in database
GPG Key ID: BB053355919D3314
2 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,42 @@
From 464ed82087b0514694ab69e2808e859cb6f13833 Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Fri, 22 Nov 2024 10:35:12 -0800
Subject: [PATCH] can_linux: initialize msghdr in a portable way
musl has padding bytes inside the msghdr struct which means initializing
full structure will cause wrong assignments, doing partial assignment is
more portable and assign the elements after that
Fixes
src/core/can_linux.c:362:71: error: incompatible pointer to integer conversion initializing 'int' with an expression of type 'void *' [-Wint-conversion]
| struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
| ^~~~
Upstream-Status: Submitted [https://github.com/CANopenTerm/CANopenTerm/pull/70]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
src/core/can_linux.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/core/can_linux.c b/src/core/can_linux.c
index d8824be..b4e7907 100644
--- a/src/core/can_linux.c
+++ b/src/core/can_linux.c
@@ -359,11 +359,16 @@ static char** get_can_interfaces(int* count)
int fd;
char buf[BUFFER_SIZE] = { 0 };
struct iovec iov = { buf, sizeof(buf) };
- struct msghdr msg = { &sa, sizeof(sa), &iov, 1, NULL, 0, 0 };
+ struct msghdr msg = { 0 };
int len;
int max_interfaces = 10;
int can_count = 0;
char** can_interfaces = (char**)os_calloc(max_interfaces * sizeof(char*), sizeof(char));
+
+ msg.msg_name = &sa;
+ msg.msg_namelen = sizeof(sa);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
struct
{

View File

@ -15,7 +15,9 @@ LIC_FILES_CHKSUM = "file://LICENSE.md;md5=10e84ea70e8c3a1fbc462f5424806474"
DEPENDS = "libinih libsdl2 lua libsocketcan pocketpy"
SRC_URI = "git://github.com/CANopenTerm/CANopenTerm.git;protocol=https;branch=main"
SRC_URI = "git://github.com/CANopenTerm/CANopenTerm.git;protocol=https;branch=main \
file://0001-can_linux-initialize-msghdr-in-a-portable-way.patch \
"
SRCREV = "5bc04e09351f68e889381e1912b0445c4f18ee32"
S = "${WORKDIR}/git"