1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

example, tests: address compiler warnings

Fix or silence all C compiler warnings discovered with (or without)
`PICKY_COMPILER=ON` (in CMake). This means all warnings showing up in
CI (gcc, clang, MSVS 2013/2015), in local tests on macOS (clang 14) and
Windows cross-builds using gcc (12) and llvm/clang (14/15).

Also fix the expression `nread -= nread` in `sftp_RW_nonblock.c`.

Cherry-picked from: #846
Closes #861
This commit is contained in:
Viktor Szakats
2023-03-20 15:46:12 +00:00
parent ec0a51db1f
commit b13936bd6a
47 changed files with 343 additions and 262 deletions

View File

@ -76,7 +76,7 @@ static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
writefd = &fd;
rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
rc = select((int)(socket_fd + 1), readfd, writefd, NULL, &timeout);
return rc;
}
@ -86,7 +86,7 @@ int main(int argc, char *argv[])
const char *hostname = "127.0.0.1";
const char *commandline = "uptime";
const char *username = NULL;
unsigned long hostaddr;
uint32_t hostaddr;
libssh2_socket_t sock;
struct sockaddr_in sin;
LIBSSH2_SESSION *session;
@ -96,7 +96,7 @@ int main(int argc, char *argv[])
int rc;
int exitcode;
char *exitsignal = (char *)"none";
int bytecount = 0;
ssize_t bytecount = 0;
#ifdef WIN32
WSADATA wsadata;
@ -230,29 +230,31 @@ int main(int argc, char *argv[])
exit(1);
}
for(;;) {
ssize_t nread;
/* loop until we block */
do {
char buffer[0x4000];
rc = libssh2_channel_read(channel, buffer, sizeof(buffer) );
if(rc > 0) {
int i;
bytecount += rc;
nread = libssh2_channel_read(channel, buffer, sizeof(buffer) );
if(nread > 0) {
ssize_t i;
bytecount += nread;
fprintf(stderr, "We read:\n");
for(i = 0; i < rc; ++i)
for(i = 0; i < nread; ++i)
fputc(buffer[i], stderr);
fprintf(stderr, "\n");
}
else {
if(rc != LIBSSH2_ERROR_EAGAIN)
if(nread != LIBSSH2_ERROR_EAGAIN)
/* no need to output this for the EAGAIN case */
fprintf(stderr, "libssh2_channel_read returned %d\n", rc);
fprintf(stderr, "libssh2_channel_read returned %d\n",
(int)nread);
}
}
while(rc > 0);
while(nread > 0);
/* this is due to blocking that would occur otherwise so we loop on
this condition */
if(rc == LIBSSH2_ERROR_EAGAIN) {
if(nread == LIBSSH2_ERROR_EAGAIN) {
waitsocket(sock, session);
}
else
@ -272,7 +274,7 @@ int main(int argc, char *argv[])
printf("\nGot signal: %s\n", exitsignal);
}
else {
printf("\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
printf("\nEXIT: %d bytecount: %d\n", exitcode, (int)bytecount);
}
libssh2_channel_free(channel);