Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error [-Werror=conversion] #3163

Open
jvasanthan opened this issue Jun 3, 2024 · 2 comments
Open

Build error [-Werror=conversion] #3163

jvasanthan opened this issue Jun 3, 2024 · 2 comments

Comments

@jvasanthan
Copy link

Hi,
I am cross-compiling v4.3.3 (tried v4.3-stable as well) and I get the following errors. The warnings are treated as errors.

libwebsockets/lib/plat/unix/unix-sockets.c:438:10: error: conversion to 'short unsigned int' from 'unsigned int' may alter its value [-Werror=conversion] ucs += ntohs(*p16++);

libwebsockets/lib/plat/unix/unix-sockets.c:450:21: error: conversion to 'short unsigned int' from 'unsigned int' may alter its value [-Werror=conversion] sll.sll_protocol = htons(0x800);

Please recommend how to fix the issue.

@lws-team
Copy link
Member

lws-team commented Jun 3, 2024

What's your platform / compiler? I can't reproduce these with gcc13.

Does this help?

diff --git a/lib/plat/unix/unix-sockets.c b/lib/plat/unix/unix-sockets.c
index e06e83b3..b72098ab 100644
--- a/lib/plat/unix/unix-sockets.c
+++ b/lib/plat/unix/unix-sockets.c
@@ -479,7 +479,7 @@ lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, size_t canned_len,
        p[3] = (uint8_t)(n);
 
        while (p16 < (uint16_t *)(p + 20))
-               ucs += ntohs(*p16++);
+               ucs += (uint32_t)ntohs(*p16++);
 
        ucs += ucs >> 16;
        ucs ^= 0xffff;
@@ -491,7 +491,7 @@ lws_plat_rawudp_broadcast(uint8_t *p, const uint8_t *canned, size_t canned_len,
 
        memset(&sll, 0, sizeof(sll));
        sll.sll_family = AF_PACKET;
-       sll.sll_protocol = htons(0x800);
+       sll.sll_protocol = (uint16_t)htons(0x800);
        sll.sll_halen = 6;
        sll.sll_ifindex = (int)if_nametoindex(iface);
        memset(sll.sll_addr, 0xff, 6);

@jvasanthan
Copy link
Author

Hi Andy,
I am using cross compiler and unfortunately its older gcc version - 6.3.0
tried your patch, didn't work. I tried to cast it in different ways none worked. I had to use -DDISABLE_WERROR to compile.
Somewhere the "unsigned short int" got promoted to" unsigned int", it could have happened inside the byte-swaping code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants