Skip to content

Commit

Permalink
examples on Windows: check for WSAStartup return code
Browse files Browse the repository at this point in the history
Fixes VS2012 code analysis warning C6031:
return value ignored: <function> could return unexpected value
  • Loading branch information
mback2k committed Dec 14, 2014
1 parent 19f1402 commit aedfba2
Show file tree
Hide file tree
Showing 22 changed files with 138 additions and 22 deletions.
7 changes: 6 additions & 1 deletion example/direct_tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ int main(int argc, char *argv[])
#ifdef WIN32
char sockopt;
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#else
int sockopt;
#endif
Expand Down
7 changes: 6 additions & 1 deletion example/scp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/scp_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/scp_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/scp_write_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_RW_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

rc = libssh2_init (0);
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_append.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_mkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_mkdir_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_write_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftp_write_sliding.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftpdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
7 changes: 6 additions & 1 deletion example/sftpdir_nonblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
8 changes: 7 additions & 1 deletion example/ssh2.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ int main(int argc, char *argv[])
char *userauthlist;
LIBSSH2_SESSION *session;
LIBSSH2_CHANNEL *channel;

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
8 changes: 7 additions & 1 deletion example/ssh2_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ int main(int argc, char *argv[])
LIBSSH2_CHANNEL *channel;
LIBSSH2_AGENT *agent = NULL;
struct libssh2_agent_publickey *identity, *prev_identity = NULL;

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1) {
Expand Down
9 changes: 8 additions & 1 deletion example/ssh2_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
WSAStartup(MAKEWORD(2,0), &wsadata);
int err;

err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1)
/* must be ip address only */
hostname = argv[1];
Expand Down
9 changes: 8 additions & 1 deletion example/ssh2_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
WSAStartup(MAKEWORD(2,0), &wsadata);
int err;

err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1)
/* must be ip address only */
hostname = argv[1];
Expand Down
7 changes: 6 additions & 1 deletion example/subsystem_netconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1)
Expand Down
7 changes: 6 additions & 1 deletion example/tcpip-forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ int main(int argc, char *argv[])

#ifdef WIN32
WSADATA wsadata;
int err;

WSAStartup(MAKEWORD(2,0), &wsadata);
err = WSAStartup(MAKEWORD(2,0), &wsadata);
if (err != 0) {
fprintf(stderr, "WSAStartup failed with error: %d\n", err);
return 1;
}
#endif

if (argc > 1)
Expand Down

0 comments on commit aedfba2

Please sign in to comment.