1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-28 01:41:49 +03:00

build: silence warnings inside FD_SET()/FD_ISSET() macros

Use an ugly workaround to silence `-Wsign-conversion` warnings triggered
by the internals of `FD_SET()`/`FD_ISSET()` macros. They've been showing
up in OmniOS CI builds when compiling `example` programs. They also have
been seen with older Cygwin and other envs and configurations.

Also scope two related variables in examples.

E.g.:
```
../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
  251 |         FD_SET(forwardsock, &fds);
      |         ^~~~~~
../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:251:9: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:251:9: warning: conversion to 'long int' from 'long unsigned int' may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
  259 |         if(rc && FD_ISSET(forwardsock, &fds)) {
      |                  ^~~~~~~~
../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'libssh2_socket_t' {aka 'int'} may change the sign of the result [-Wsign-conversion]
../../example/direct_tcpip.c:259:18: warning: conversion to 'long unsigned int' from 'long int' may change the sign of the result [-Wsign-conversion]
```
Ref: https://github.com/libssh2/libssh2/actions/runs/8854199687/job/24316762831#step:3:2020

Closes #1379
This commit is contained in:
Viktor Szakats
2024-04-29 00:55:34 +02:00
parent 6556bfbd43
commit 323a14b2ca
13 changed files with 170 additions and 2 deletions

View File

@ -66,7 +66,6 @@ int main(int argc, char *argv[])
LIBSSH2_SESSION *session = NULL;
LIBSSH2_LISTENER *listener = NULL;
LIBSSH2_CHANNEL *channel = NULL;
fd_set fds;
struct timeval tv;
ssize_t len, wr;
char buf[16384];
@ -245,8 +244,16 @@ int main(int argc, char *argv[])
libssh2_session_set_blocking(session, 0);
for(;;) {
fd_set fds;
FD_ZERO(&fds);
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
FD_SET(forwardsock, &fds);
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
tv.tv_sec = 0;
tv.tv_usec = 100000;
rc = select((int)(forwardsock + 1), &fds, NULL, NULL, &tv);
@ -254,7 +261,14 @@ int main(int argc, char *argv[])
fprintf(stderr, "failed to select().\n");
goto shutdown;
}
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
if(rc && FD_ISSET(forwardsock, &fds)) {
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
ssize_t nwritten;
len = recv(forwardsock, buf, sizeof(buf), 0);
if(len < 0) {