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:
@ -74,7 +74,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;
|
||||
}
|
||||
@ -85,7 +85,7 @@ int main(int argc, char *argv[])
|
||||
const char *commandline = "uptime";
|
||||
const char *username = "user";
|
||||
const char *password = "password";
|
||||
unsigned long hostaddr;
|
||||
uint32_t hostaddr;
|
||||
libssh2_socket_t sock;
|
||||
struct sockaddr_in sin;
|
||||
const char *fingerprint;
|
||||
@ -94,7 +94,7 @@ int main(int argc, char *argv[])
|
||||
int rc;
|
||||
int exitcode;
|
||||
char *exitsignal = (char *)"none";
|
||||
int bytecount = 0;
|
||||
ssize_t bytecount = 0;
|
||||
size_t len;
|
||||
LIBSSH2_KNOWNHOSTS *nh;
|
||||
int type;
|
||||
@ -259,25 +259,27 @@ 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 */
|
||||
@ -300,7 +302,8 @@ int main(int argc, char *argv[])
|
||||
if(exitsignal)
|
||||
fprintf(stderr, "\nGot signal: %s\n", exitsignal);
|
||||
else
|
||||
fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
|
||||
fprintf(stderr, "\nEXIT: %d bytecount: %d\n",
|
||||
exitcode, (int)bytecount);
|
||||
|
||||
libssh2_channel_free(channel);
|
||||
channel = NULL;
|
||||
|
Reference in New Issue
Block a user