Skip to content

Commit

Permalink
fix several compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtse committed Mar 20, 2012
1 parent e6a89cb commit c6825b7
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 34 deletions.
6 changes: 3 additions & 3 deletions lib/connect.c
Expand Up @@ -93,7 +93,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error);

static void
tcpkeepalive(struct SessionHandle *data,
int sockfd)
curl_socket_t sockfd)
{
int optval = data->set.tcp_keepalive?1:0;

Expand All @@ -104,14 +104,14 @@ tcpkeepalive(struct SessionHandle *data,
}
else {
#ifdef TCP_KEEPIDLE
optval = data->set.tcp_keepidle;
optval = curlx_sltosi(data->set.tcp_keepidle);
if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE,
(void *)&optval, sizeof(optval)) < 0) {
infof(data, "Failed to set TCP_KEEPIDLE on fd %d\n", sockfd);
}
#endif
#ifdef TCP_KEEPINTVL
optval = data->set.tcp_keepintvl;
optval = curlx_sltosi(data->set.tcp_keepintvl);
if(setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL,
(void *)&optval, sizeof(optval)) < 0) {
infof(data, "Failed to set TCP_KEEPINTVL on fd %d\n", sockfd);
Expand Down
3 changes: 2 additions & 1 deletion lib/md4.c
Expand Up @@ -27,6 +27,7 @@
#ifdef USE_NSS

#include "curl_md4.h"
#include "warnless.h"

typedef unsigned int UINT4;

Expand Down Expand Up @@ -275,7 +276,7 @@ void Curl_md4it(unsigned char *output, const unsigned char *input, size_t len)
{
MD4_CTX ctx;
MD4Init(&ctx);
MD4Update(&ctx, input, (unsigned int)len);
MD4Update(&ctx, input, curlx_uztoui(len));
MD4Final(output, &ctx);
}
#endif /* USE_NSS */
5 changes: 3 additions & 2 deletions lib/md5.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand All @@ -26,6 +26,7 @@

#include "curl_md5.h"
#include "curl_hmac.h"
#include "warnless.h"

#ifdef USE_GNUTLS_NETTLE

Expand Down Expand Up @@ -412,7 +413,7 @@ void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
{
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, input, (unsigned int)strlen((char *)input));
MD5_Update(&ctx, input, curlx_uztoui(strlen((char *)input)));
MD5_Final(outbuffer, &ctx);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/smtp.c
Expand Up @@ -757,15 +757,15 @@ static CURLcode smtp_state_authcram_resp(struct connectdata *conn,
/* Compute digest. */
ctxt = Curl_HMAC_init(Curl_HMAC_MD5,
(const unsigned char *) conn->passwd,
(unsigned int)(strlen(conn->passwd)));
curlx_uztoui(strlen(conn->passwd)));

if(!ctxt) {
Curl_safefree(chlg);
return CURLE_OUT_OF_MEMORY;
}

if(chlglen > 0)
Curl_HMAC_update(ctxt, chlg, (unsigned int)(chlglen));
Curl_HMAC_update(ctxt, chlg, curlx_uztoui(chlglen));

Curl_safefree(chlg);

Expand Down
50 changes: 25 additions & 25 deletions lib/ssh.c
Expand Up @@ -225,7 +225,7 @@ kbd_callback(const char *name, int name_len, const char *instruction,
#endif /* CURL_LIBSSH2_DEBUG */
if(num_prompts == 1) {
responses[0].text = strdup(conn->passwd);
responses[0].length = (unsigned int)strlen(conn->passwd);
responses[0].length = curlx_uztoui(strlen(conn->passwd));
}
(void)prompts;
(void)abstract;
Expand Down Expand Up @@ -734,7 +734,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
*/
sshc->authlist = libssh2_userauth_list(sshc->ssh_session,
conn->user,
(unsigned int)strlen(conn->user));
curlx_uztoui(strlen(conn->user)));

if(!sshc->authlist) {
if((err = libssh2_session_last_errno(sshc->ssh_session)) ==
Expand Down Expand Up @@ -827,8 +827,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
*/
rc = libssh2_userauth_publickey_fromfile_ex(sshc->ssh_session,
conn->user,
(unsigned int)
strlen(conn->user),
curlx_uztoui(
strlen(conn->user)),
sshc->rsa_pub,
sshc->rsa, sshc->passphrase);
if(rc == LIBSSH2_ERROR_EAGAIN) {
Expand Down Expand Up @@ -866,9 +866,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_AUTH_PASS:
rc = libssh2_userauth_password_ex(sshc->ssh_session, conn->user,
(unsigned int)strlen(conn->user),
curlx_uztoui(strlen(conn->user)),
conn->passwd,
(unsigned int)strlen(conn->passwd),
curlx_uztoui(strlen(conn->passwd)),
NULL);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand Down Expand Up @@ -911,8 +911,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* Authentication failed. Continue with keyboard-interactive now. */
rc = libssh2_userauth_keyboard_interactive_ex(sshc->ssh_session,
conn->user,
(unsigned int)
strlen(conn->user),
curlx_uztoui(
strlen(conn->user)),
&kbd_callback);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand Down Expand Up @@ -1271,7 +1271,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
* first. This takes an extra protocol round trip.
*/
rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshc->quote_path2,
(unsigned int)strlen(sshc->quote_path2),
curlx_uztoui(strlen(sshc->quote_path2)),
LIBSSH2_SFTP_STAT,
&sshc->quote_attrs);
if(rc == LIBSSH2_ERROR_EAGAIN) {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_SFTP_QUOTE_SETSTAT:
rc = libssh2_sftp_stat_ex(sshc->sftp_session, sshc->quote_path2,
(unsigned int)strlen(sshc->quote_path2),
curlx_uztoui(strlen(sshc->quote_path2)),
LIBSSH2_SFTP_SETSTAT,
&sshc->quote_attrs);
if(rc == LIBSSH2_ERROR_EAGAIN) {
Expand All @@ -1374,9 +1374,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_SFTP_QUOTE_SYMLINK:
rc = libssh2_sftp_symlink_ex(sshc->sftp_session, sshc->quote_path1,
(unsigned int)strlen(sshc->quote_path1),
curlx_uztoui(strlen(sshc->quote_path1)),
sshc->quote_path2,
(unsigned int)strlen(sshc->quote_path2),
curlx_uztoui(strlen(sshc->quote_path2)),
LIBSSH2_SFTP_SYMLINK);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand All @@ -1399,7 +1399,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_SFTP_QUOTE_MKDIR:
rc = libssh2_sftp_mkdir_ex(sshc->sftp_session, sshc->quote_path1,
(unsigned int)strlen(sshc->quote_path1),
curlx_uztoui(strlen(sshc->quote_path1)),
data->set.new_directory_perms);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand All @@ -1419,9 +1419,9 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_SFTP_QUOTE_RENAME:
rc = libssh2_sftp_rename_ex(sshc->sftp_session, sshc->quote_path1,
(unsigned int)strlen(sshc->quote_path1),
curlx_uztoui(strlen(sshc->quote_path1)),
sshc->quote_path2,
(unsigned int)strlen(sshc->quote_path2),
curlx_uztoui(strlen(sshc->quote_path2)),
LIBSSH2_SFTP_RENAME_OVERWRITE |
LIBSSH2_SFTP_RENAME_ATOMIC |
LIBSSH2_SFTP_RENAME_NATIVE);
Expand All @@ -1446,7 +1446,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_SFTP_QUOTE_RMDIR:
rc = libssh2_sftp_rmdir_ex(sshc->sftp_session, sshc->quote_path1,
(unsigned int)strlen(sshc->quote_path1));
curlx_uztoui(strlen(sshc->quote_path1)));
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
Expand All @@ -1465,7 +1465,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

case SSH_SFTP_QUOTE_UNLINK:
rc = libssh2_sftp_unlink_ex(sshc->sftp_session, sshc->quote_path1,
(unsigned int)strlen(sshc->quote_path1));
curlx_uztoui(strlen(sshc->quote_path1)));
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
Expand Down Expand Up @@ -1509,7 +1509,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
LIBSSH2_SFTP_ATTRIBUTES attrs;
if(data->state.resume_from < 0) {
rc = libssh2_sftp_stat_ex(sshc->sftp_session, sftp_scp->path,
(unsigned int)strlen(sftp_scp->path),
curlx_uztoui(strlen(sftp_scp->path)),
LIBSSH2_SFTP_STAT, &attrs);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand Down Expand Up @@ -1540,7 +1540,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)

sshc->sftp_handle =
libssh2_sftp_open_ex(sshc->sftp_session, sftp_scp->path,
(unsigned int)strlen(sftp_scp->path),
curlx_uztoui(strlen(sftp_scp->path)),
flags, data->set.new_file_perms,
LIBSSH2_SFTP_OPENFILE);

Expand Down Expand Up @@ -1699,7 +1699,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
case SSH_SFTP_CREATE_DIRS_MKDIR:
/* 'mode' - parameter is preliminary - default to 0644 */
rc = libssh2_sftp_mkdir_ex(sshc->sftp_session, sftp_scp->path,
(unsigned int)strlen(sftp_scp->path),
curlx_uztoui(strlen(sftp_scp->path)),
data->set.new_directory_perms);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand Down Expand Up @@ -1733,8 +1733,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
*/
sshc->sftp_handle = libssh2_sftp_open_ex(sshc->sftp_session,
sftp_scp->path,
(unsigned int)
strlen(sftp_scp->path),
curlx_uztoui(
strlen(sftp_scp->path)),
0, 0, LIBSSH2_SFTP_OPENDIR);
if(!sshc->sftp_handle) {
if(libssh2_session_last_errno(sshc->ssh_session) ==
Expand Down Expand Up @@ -1875,7 +1875,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
sshc->readdir_len =
libssh2_sftp_symlink_ex(sshc->sftp_session,
sshc->readdir_linkPath,
(unsigned int) strlen(sshc->readdir_linkPath),
curlx_uztoui(strlen(sshc->readdir_linkPath)),
sshc->readdir_filename,
PATH_MAX, LIBSSH2_SFTP_READLINK);
if(sshc->readdir_len == LIBSSH2_ERROR_EAGAIN) {
Expand Down Expand Up @@ -1961,7 +1961,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
*/
sshc->sftp_handle =
libssh2_sftp_open_ex(sshc->sftp_session, sftp_scp->path,
(unsigned int)strlen(sftp_scp->path),
curlx_uztoui(strlen(sftp_scp->path)),
LIBSSH2_FXF_READ, data->set.new_file_perms,
LIBSSH2_SFTP_OPENFILE);
if(!sshc->sftp_handle) {
Expand All @@ -1988,7 +1988,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
LIBSSH2_SFTP_ATTRIBUTES attrs;

rc = libssh2_sftp_stat_ex(sshc->sftp_session, sftp_scp->path,
(unsigned int)strlen(sftp_scp->path),
curlx_uztoui(strlen(sftp_scp->path)),
LIBSSH2_SFTP_STAT, &attrs);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand Down
20 changes: 20 additions & 0 deletions lib/warnless.c
Expand Up @@ -185,13 +185,33 @@ unsigned long curlx_uztoul(size_t uznum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif

DEBUGASSERT(uznum <= (size_t) CURL_MASK_ULONG);
return (unsigned long)(uznum & (size_t) CURL_MASK_ULONG);

#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}

/*
** unsigned size_t to unsigned int
*/

unsigned int curlx_uztoui(size_t uznum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif

DEBUGASSERT(uznum <= (size_t) CURL_MASK_UINT);
return (unsigned int)(uznum & (size_t) CURL_MASK_UINT);

#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}

/*
** signed long to signed int
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/warnless.h
Expand Up @@ -30,6 +30,8 @@ int curlx_uztosi(size_t uznum);

unsigned long curlx_uztoul(size_t uznum);

unsigned int curlx_uztoui(size_t uznum);

int curlx_sltosi(long slnum);

unsigned int curlx_sltoui(long slnum);
Expand Down
4 changes: 3 additions & 1 deletion tests/libtest/testtrace.c
Expand Up @@ -91,11 +91,13 @@ int libtest_debug_cb(CURL *handle, curl_infotype type,
struct timeval tv;
struct tm *now;
char timebuf[20];
char *timestr;
time_t secs;

(void)handle;

timebuf[0] = '\0';
timestr = &timebuf[0];

if(trace_cfg->tracetime) {
tv = tutil_tvnow();
Expand All @@ -111,7 +113,7 @@ int libtest_debug_cb(CURL *handle, curl_infotype type,

switch (type) {
case CURLINFO_TEXT:
fprintf(stderr, "%s== Info: %s", &timebuf[0], data);
fprintf(stderr, "%s== Info: %s", timestr, data);
default: /* in case a new one is introduced to shock us */
return 0;

Expand Down

0 comments on commit c6825b7

Please sign in to comment.