mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-31 00:03:08 +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:
@ -65,14 +65,14 @@ 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;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned long hostaddr;
|
||||
uint32_t hostaddr;
|
||||
libssh2_socket_t sock;
|
||||
int i, auth_pw = 1;
|
||||
struct sockaddr_in sin;
|
||||
@ -90,7 +90,7 @@ int main(int argc, char *argv[])
|
||||
char *ptr;
|
||||
struct stat fileinfo;
|
||||
time_t start;
|
||||
long total = 0;
|
||||
libssh2_struct_stat_size total = 0;
|
||||
int duration;
|
||||
size_t prev;
|
||||
|
||||
@ -210,7 +210,7 @@ int main(int argc, char *argv[])
|
||||
/* Send a file via scp. The mode parameter must only have permissions! */
|
||||
do {
|
||||
channel = libssh2_scp_send(session, scppath, fileinfo.st_mode & 0777,
|
||||
(unsigned long)fileinfo.st_size);
|
||||
(size_t)fileinfo.st_size);
|
||||
|
||||
if((!channel) && (libssh2_session_last_errno(session) !=
|
||||
LIBSSH2_ERROR_EAGAIN)) {
|
||||
@ -236,22 +236,23 @@ int main(int argc, char *argv[])
|
||||
|
||||
prev = 0;
|
||||
do {
|
||||
while((rc = libssh2_channel_write(channel, ptr, nread)) ==
|
||||
ssize_t nwritten;
|
||||
while((nwritten = libssh2_channel_write(channel, ptr, nread)) ==
|
||||
LIBSSH2_ERROR_EAGAIN) {
|
||||
waitsocket(sock, session);
|
||||
prev = 0;
|
||||
}
|
||||
if(rc < 0) {
|
||||
fprintf(stderr, "ERROR %d total %ld / %d prev %d\n", rc,
|
||||
total, (int)nread, (int)prev);
|
||||
if(nwritten < 0) {
|
||||
fprintf(stderr, "ERROR %d total %ld / %d prev %d\n",
|
||||
(int)nwritten, (long)total, (int)nread, (int)prev);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
prev = nread;
|
||||
|
||||
/* rc indicates how many bytes were written this time */
|
||||
nread -= rc;
|
||||
ptr += rc;
|
||||
/* nwritten indicates how many bytes were written this time */
|
||||
nread -= nwritten;
|
||||
ptr += nwritten;
|
||||
}
|
||||
} while(nread);
|
||||
} while(!nread); /* only continue if nread was drained */
|
||||
@ -259,7 +260,7 @@ int main(int argc, char *argv[])
|
||||
duration = (int)(time(NULL)-start);
|
||||
|
||||
fprintf(stderr, "%ld bytes in %d seconds makes %.1f bytes/sec\n",
|
||||
total, duration, total/(double)duration);
|
||||
(long)total, duration, (double)total / duration);
|
||||
|
||||
fprintf(stderr, "Sending EOF\n");
|
||||
while(libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);
|
||||
|
Reference in New Issue
Block a user