From bcd1c7c2e92d41ab02163a36a1ab9d5a7afd83a9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 26 Feb 2010 16:42:33 +0000 Subject: fix compiler warning --- lib/curlx.h | 1 + lib/warnless.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- lib/warnless.h | 2 ++ 3 files changed, 73 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/curlx.h b/lib/curlx.h index 1f84e6d0a..d5de599f5 100644 --- a/lib/curlx.h +++ b/lib/curlx.h @@ -61,6 +61,7 @@ curlx_ultous() curlx_ultouc() + curlx_uztosi() */ /* Now setup curlx_ * names for the functions that are to become curlx_ and diff --git a/lib/warnless.c b/lib/warnless.c index ffbcaa3f1..232ff8027 100644 --- a/lib/warnless.c +++ b/lib/warnless.c @@ -25,6 +25,52 @@ #include "warnless.h" +#define CURL_MASK_SCHAR 0x7F +#define CURL_MASK_UCHAR 0xFF + +#if (SIZEOF_SHORT == 2) +# define CURL_MASK_SSHORT 0x7FFF +# define CURL_MASK_USHORT 0xFFFF +#elif (SIZEOF_SHORT == 4) +# define CURL_MASK_SSHORT 0x7FFFFFFF +# define CURL_MASK_USHORT 0xFFFFFFFF +#elif (SIZEOF_SHORT == 8) +# define CURL_MASK_SSHORT 0x7FFFFFFFFFFFFFFF +# define CURL_MASK_USHORT 0xFFFFFFFFFFFFFFFF +#endif + +#if (SIZEOF_INT == 2) +# define CURL_MASK_SINT 0x7FFF +# define CURL_MASK_UINT 0xFFFF +#elif (SIZEOF_INT == 4) +# define CURL_MASK_SINT 0x7FFFFFFF +# define CURL_MASK_UINT 0xFFFFFFFF +#elif (SIZEOF_INT == 8) +# define CURL_MASK_SINT 0x7FFFFFFFFFFFFFFF +# define CURL_MASK_UINT 0xFFFFFFFFFFFFFFFF +#elif (SIZEOF_INT == 16) +# define CURL_MASK_SINT 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +# define CURL_MASK_UINT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF +#endif + +#if (SIZEOF_LONG == 2) +# define CURL_MASK_SLONG 0x7FFFL +# define CURL_MASK_ULONG 0xFFFFUL +#elif (SIZEOF_LONG == 4) +# define CURL_MASK_SLONG 0x7FFFFFFFL +# define CURL_MASK_ULONG 0xFFFFFFFFUL +#elif (SIZEOF_LONG == 8) +# define CURL_MASK_SLONG 0x7FFFFFFFFFFFFFFFL +# define CURL_MASK_ULONG 0xFFFFFFFFFFFFFFFFUL +#elif (SIZEOF_LONG == 16) +# define CURL_MASK_SLONG 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL +# define CURL_MASK_ULONG 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL +#endif + +/* +** unsigned long to unsigned short +*/ + unsigned short curlx_ultous(unsigned long ulnum) { #ifdef __INTEL_COMPILER @@ -32,13 +78,17 @@ unsigned short curlx_ultous(unsigned long ulnum) # pragma warning(disable:810) /* conversion may lose significant bits */ #endif - return (unsigned short)(ulnum & 0xFFFFUL); + return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT); #ifdef __INTEL_COMPILER # pragma warning(pop) #endif } +/* +** unsigned long to unsigned char +*/ + unsigned char curlx_ultouc(unsigned long ulnum) { #ifdef __INTEL_COMPILER @@ -46,7 +96,25 @@ unsigned char curlx_ultouc(unsigned long ulnum) # pragma warning(disable:810) /* conversion may lose significant bits */ #endif - return (unsigned char)(ulnum & 0xFFUL); + return (unsigned char)(ulnum & (unsigned long) CURL_MASK_UCHAR); + +#ifdef __INTEL_COMPILER +# pragma warning(pop) +#endif +} + +/* +** size_t to signed int +*/ + +int curlx_uztosi(size_t uznum) +{ +#ifdef __INTEL_COMPILER +# pragma warning(push) +# pragma warning(disable:810) /* conversion may lose significant bits */ +#endif + + return (int)(uznum & (size_t) CURL_MASK_SINT); #ifdef __INTEL_COMPILER # pragma warning(pop) diff --git a/lib/warnless.h b/lib/warnless.h index 0976088cd..41688de41 100644 --- a/lib/warnless.h +++ b/lib/warnless.h @@ -27,4 +27,6 @@ unsigned short curlx_ultous(unsigned long ulnum); unsigned char curlx_ultouc(unsigned long ulnum); +int curlx_uztosi(size_t uznum); + #endif /* HEADER_CURL_WARNLESS_H */ -- cgit v1.2.3