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

Misleading type cast in function modbus_tcp_listen() #721

Closed
franzhollerer opened this issue Nov 3, 2023 · 1 comment
Closed

Misleading type cast in function modbus_tcp_listen() #721

franzhollerer opened this issue Nov 3, 2023 · 1 comment

Comments

@franzhollerer
Copy link

There is a misleading type cast in function modbus_tcp_listen().

I think

    if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (char *) &enable, sizeof(enable)) ==

should be replaced by

    if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, (void *) &enable, sizeof(enable)) ==

similar to modbus_tcp_pi_listen(), or

    if (setsockopt(new_s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) ==

I prefer the later one as to my understanding there is no type cast needed at this point at all.

@skeeto
Copy link

skeeto commented Aug 15, 2024

dde16d5 breaks Windows builds with GCC 14 and later, requiring -fpermissive in order to compile. Winsock setsockopt uses const char * for optval rather than const void * as it is on POSIX.

int WSAAPI setsockopt(
  [in] SOCKET     s,
  [in] int        level,
  [in] int        optname,
  [in] const char *optval,
  [in] int        optlen
);

GCC 14 and later is strict about pointer casts and rejects the implicit cast from int * to const char *. The explicit char * cast was probably used to silence the warning that is now an error.

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