warnings: fix another 'conversion may lose significant bits' compiler warning
authorYang Tse <yangsita@gmail.com>
Sun, 21 Aug 2011 17:56:06 +0000 (19:56 +0200)
committerYang Tse <yangsita@gmail.com>
Sun, 21 Aug 2011 17:56:06 +0000 (19:56 +0200)
ares_expand_name.c
ares_nowarn.c
ares_nowarn.h

index e3eccd2f74d2e3591133985b81f02c4c7199df1d..71ff0dae0ab5b4ee621843c3caa5dec4e623ab42 100644 (file)
@@ -1,5 +1,5 @@
 
-/* Copyright 1998 by the Massachusetts Institute of Technology.
+/* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
  *
  * Permission to use, copy, modify, and distribute this
  * software and its documentation for any purpose and without
@@ -33,6 +33,7 @@
 
 #include <stdlib.h>
 #include "ares.h"
+#include "ares_nowarn.h"
 #include "ares_private.h" /* for the memdebug */
 
 static int name_length(const unsigned char *encoded, const unsigned char *abuf,
@@ -91,9 +92,9 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
     /* indirect root label (like 0xc0 0x0c) is 2 bytes long (stupid, but
        valid) */
     if ((*encoded & INDIR_MASK) == INDIR_MASK)
-      *enclen = 2;
+      *enclen = 2L;
     else
-      *enclen = 1;  /* the caller should move one byte to get past this */
+      *enclen = 1L;  /* the caller should move one byte to get past this */
 
     return ARES_SUCCESS;
   }
@@ -106,7 +107,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
         {
           if (!indir)
             {
-              *enclen = p + 2 - encoded;
+              *enclen = aresx_uztosl(p + 2U - encoded);
               indir = 1;
             }
           p = abuf + ((*p & ~INDIR_MASK) << 8 | *(p + 1));
@@ -126,7 +127,7 @@ int ares_expand_name(const unsigned char *encoded, const unsigned char *abuf,
         }
     }
   if (!indir)
-    *enclen = p + 1 - encoded;
+    *enclen = aresx_uztosl(p + 1U - encoded);
 
   /* Nuke the trailing period if we wrote one. */
   if (q > *s)
index 6c92f6fb77293ac657d9139bc2d464c8afe804c2..0056bb82e67327c16b0e01c45940b01e8ccab754 100644 (file)
 #elif (SIZEOF_INT == 16)
 #  define CARES_MASK_SINT  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
 #  define CARES_MASK_UINT  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+#else
+#  error "SIZEOF_INT not defined"
 #endif
 
+#if (CARES_SIZEOF_LONG == 2)
+#  define CARES_MASK_SLONG  0x7FFFL
+#  define CARES_MASK_ULONG  0xFFFFUL
+#elif (CARES_SIZEOF_LONG == 4)
+#  define CARES_MASK_SLONG  0x7FFFFFFFL
+#  define CARES_MASK_ULONG  0xFFFFFFFFUL
+#elif (CARES_SIZEOF_LONG == 8)
+#  define CARES_MASK_SLONG  0x7FFFFFFFFFFFFFFFL
+#  define CARES_MASK_ULONG  0xFFFFFFFFFFFFFFFFUL
+#elif (CARES_SIZEOF_LONG == 16)
+#  define CARES_MASK_SLONG  0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFL
+#  define CARES_MASK_ULONG  0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFUL
+#else
+#  error "CARES_SIZEOF_LONG not defined"
+#endif
+
+/*
+** unsigned size_t to signed long
+*/
+
+long aresx_uztosl(size_t uznum)
+{
+#ifdef __INTEL_COMPILER
+#  pragma warning(push)
+#  pragma warning(disable:810) /* conversion may lose significant bits */
+#endif
+
+  return (long)(uznum & (size_t) CARES_MASK_SLONG);
+
+#ifdef __INTEL_COMPILER
+#  pragma warning(pop)
+#endif
+}
+
 /*
 ** unsigned size_t to signed int
 */
index af112b9f2c2b3a25a37f636f53b2b7b0eda0f500..c593e4592cc50267f28ecee095453f8afbd2b608 100644 (file)
@@ -17,8 +17,8 @@
  * without express or implied warranty.
  */
 
-int aresx_uztosi(size_t uznum);
-
+long  aresx_uztosl(size_t uznum);
+int   aresx_uztosi(size_t uznum);
 short aresx_uztoss(size_t uznum);
 
 short aresx_sitoss(int sinum);