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 22, 2012
1 parent c83de6d commit 3c80309
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
8 changes: 4 additions & 4 deletions lib/base64.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 Down Expand Up @@ -58,11 +58,11 @@ static void decodeQuantum(unsigned char *dest, const char *src)
x = (x << 6);
}

dest[2] = curlx_ultouc(x);
dest[2] = curlx_ultouc(x & 0xFFUL);
x >>= 8;
dest[1] = curlx_ultouc(x);
dest[1] = curlx_ultouc(x & 0xFFUL);
x >>= 8;
dest[0] = curlx_ultouc(x);
dest[0] = curlx_ultouc(x & 0xFFUL);
}

/*
Expand Down
6 changes: 4 additions & 2 deletions lib/http_digest.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 Down Expand Up @@ -34,6 +34,7 @@
#include "url.h" /* for Curl_safefree() */
#include "curl_memory.h"
#include "non-ascii.h" /* included for Curl_convert_... prototypes */
#include "warnless.h"

#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
Expand Down Expand Up @@ -416,7 +417,8 @@ CURLcode Curl_output_digest(struct connectdata *conn,
*/
if(authp->iestyle && ((tmp = strchr((char *)uripath, '?')) != NULL)) {
md5this = (unsigned char *)aprintf("%s:%.*s", request,
(int)(tmp - (char *)uripath), uripath);
curlx_sztosi(tmp - (char *)uripath),
uripath);
}
else
md5this = (unsigned char *)aprintf("%s:%s", request, uripath);
Expand Down
6 changes: 5 additions & 1 deletion lib/ssh.c
Expand Up @@ -108,6 +108,10 @@
have their definition hidden well */
#endif

#define sftp_libssh2_realpath(s,p,t,m) \
libssh2_sftp_symlink_ex((s), (p), curlx_uztoui(strlen(p)), \
(t), (m), LIBSSH2_SFTP_REALPATH)

/* Local functions: */
static const char *sftp_libssh2_strerror(unsigned long err);
static LIBSSH2_ALLOC_FUNC(my_libssh2_malloc);
Expand Down Expand Up @@ -982,7 +986,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/*
* Get the "home" directory
*/
rc = libssh2_sftp_realpath(sshc->sftp_session, ".",
rc = sftp_libssh2_realpath(sshc->sftp_session, ".",
tempHome, PATH_MAX-1);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
Expand Down
17 changes: 10 additions & 7 deletions lib/ssluse.c
Expand Up @@ -145,7 +145,7 @@
static char global_passwd[64];
#endif

static int passwd_callback(char *buf, int num, int verify
static int passwd_callback(char *buf, int num, int encrypting
#ifdef HAVE_USERDATA_IN_PWD_CALLBACK
/* This was introduced in 0.9.4, we can set this
using SSL_CTX_set_default_passwd_cb_userdata()
Expand All @@ -154,12 +154,13 @@ static int passwd_callback(char *buf, int num, int verify
#endif
)
{
if(verify)
fprintf(stderr, "%s\n", buf);
else {
if(num > (int)strlen((char *)global_passwd)) {
strcpy(buf, global_passwd);
return (int)strlen(buf);
DEBUGASSERT(0 == encrypting);

if(!encrypting) {
int klen = curlx_uztosi(strlen((char *)global_passwd));
if(num > klen) {
memcpy(buf, global_passwd, klen+1);
return klen;
}
}
return 0;
Expand Down Expand Up @@ -339,6 +340,8 @@ int cert_stuff(struct connectdata *conn,
size_t len = strlen(data->set.str[STRING_KEY_PASSWD]);
if(len < sizeof(global_passwd))
memcpy(global_passwd, data->set.str[STRING_KEY_PASSWD], len+1);
else
global_passwd[0] = '\0';
#else
/*
* We set the password in the callback userdata
Expand Down
8 changes: 8 additions & 0 deletions lib/warnless.c
Expand Up @@ -131,6 +131,7 @@ unsigned short curlx_ultous(unsigned long ulnum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif

DEBUGASSERT(ulnum <= (unsigned long) CURL_MASK_USHORT);
return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);

#ifdef __INTEL_COMPILER
Expand All @@ -149,6 +150,7 @@ unsigned char curlx_ultouc(unsigned long ulnum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif

DEBUGASSERT(ulnum <= (unsigned long) CURL_MASK_UCHAR);
return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR);

#ifdef __INTEL_COMPILER
Expand All @@ -167,6 +169,7 @@ int curlx_uztosi(size_t uznum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif

DEBUGASSERT(uznum <= (size_t) CURL_MASK_SINT);
return (int)(uznum & (size_t) CURL_MASK_SINT);

#ifdef __INTEL_COMPILER
Expand Down Expand Up @@ -224,6 +227,7 @@ int curlx_sltosi(long slnum)
#endif

DEBUGASSERT(slnum >= 0);
DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_SINT);
return (int)(slnum & (long) CURL_MASK_SINT);

#ifdef __INTEL_COMPILER
Expand All @@ -243,6 +247,7 @@ unsigned int curlx_sltoui(long slnum)
#endif

DEBUGASSERT(slnum >= 0);
DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_UINT);
return (unsigned int)(slnum & (long) CURL_MASK_UINT);

#ifdef __INTEL_COMPILER
Expand All @@ -262,6 +267,7 @@ unsigned short curlx_sltous(long slnum)
#endif

DEBUGASSERT(slnum >= 0);
DEBUGASSERT((unsigned long) slnum <= (unsigned long) CURL_MASK_USHORT);
return (unsigned short)(slnum & (long) CURL_MASK_USHORT);

#ifdef __INTEL_COMPILER
Expand All @@ -280,6 +286,7 @@ ssize_t curlx_uztosz(size_t uznum)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif

DEBUGASSERT(uznum <= (size_t) CURL_MASK_SSIZE_T);
return (ssize_t)(uznum & (size_t) CURL_MASK_SSIZE_T);

#ifdef __INTEL_COMPILER
Expand Down Expand Up @@ -318,6 +325,7 @@ int curlx_sztosi(ssize_t sznum)
#endif

DEBUGASSERT(sznum >= 0);
DEBUGASSERT((size_t) sznum <= (size_t) CURL_MASK_SINT);
return (int)(sznum & (ssize_t) CURL_MASK_SINT);

#ifdef __INTEL_COMPILER
Expand Down
4 changes: 2 additions & 2 deletions tests/libtest/Makefile.inc
Expand Up @@ -119,7 +119,7 @@ lib549_SOURCES = lib549.c $(SUPPORTFILES)

lib555_SOURCES = lib555.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)

lib552_SOURCES = lib552.c $(SUPPORTFILES)
lib552_SOURCES = lib552.c $(SUPPORTFILES) $(WARNLESS)

lib553_SOURCES = lib553.c $(SUPPORTFILES)

Expand Down Expand Up @@ -154,7 +154,7 @@ lib569_SOURCES = lib569.c $(SUPPORTFILES)

lib570_SOURCES = lib570.c $(SUPPORTFILES)

lib571_SOURCES = lib571.c $(SUPPORTFILES)
lib571_SOURCES = lib571.c $(SUPPORTFILES) $(WARNLESS)

lib572_SOURCES = lib572.c $(SUPPORTFILES)

Expand Down
6 changes: 4 additions & 2 deletions tests/libtest/lib552.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 @@ -25,6 +25,7 @@

#include "test.h"

#include "warnless.h"
#include "memdebug.h"

struct data {
Expand Down Expand Up @@ -136,7 +137,8 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)

static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
printf("%.*s", (int)(size * nmemb), (char *)ptr);
int amount = curlx_uztosi(size * nmemb);
printf("%.*s", amount, (char *)ptr);
(void)stream;
return size * nmemb;
}
Expand Down
7 changes: 5 additions & 2 deletions tests/libtest/lib571.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 Down Expand Up @@ -39,6 +39,7 @@

#include <curl/mprintf.h>

#include "warnless.h"
#include "memdebug.h"

#define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
Expand All @@ -54,12 +55,14 @@ static int rtp_packet_count = 0;
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
char *data = (char *)ptr;
int channel = RTP_PKT_CHANNEL(data);
int message_size = (int)(size * nmemb) - 4;
int message_size;
int coded_size = RTP_PKT_LENGTH(data);
size_t failure = (size * nmemb) ? 0 : 1;
int i;
(void)stream;

message_size = curlx_uztosi(size * nmemb) - 4;

printf("RTP: message size %d, channel %d\n", message_size, channel);
if(message_size != coded_size) {
printf("RTP embedded size (%d) does not match the write size (%d).\n",
Expand Down
2 changes: 1 addition & 1 deletion tests/libtest/testtrace.c
Expand Up @@ -113,7 +113,7 @@ int libtest_debug_cb(CURL *handle, curl_infotype type,

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

Expand Down

0 comments on commit 3c80309

Please sign in to comment.