On Thu, 28 Jun 2007 21:30:27 -0400
Alex Burger <[EMAIL PROTECTED]> wrote:

> Mitsuru Chinen wrote:
> > On Thu, 28 Jun 2007 22:06:03 +0900
> > Mitsuru Chinen <[EMAIL PROTECTED]> wrote:
> >
> >   
> >> Then, how about the attached patch?
> >>     
> The patch fixes the long long issue, but doesn't address the 
> HAVE_INTMAX_T issue.  As I mentioned in my original email, should we change:
> 
>  typedef long long intmax_t;
>  typedef unsigned long long uintmax_t;
> 
> to:
> 
>  typedef int64_t intmax_t;
>  typedef uint64_t uintmax_t;
> 
> I can test the patch and any other changes on the weekend.

OK. Thanks!
But I reviewed the code, I'm getting to think it's better to
prepare both case than to replace long long to uint64_t. 
And at the snmplib/snmp_client.c, I think it's better to prepare
code for both unsigned long long and uintmax_t.

According to the preprocess of include/net-snmp/types.h, there is a
case where the bit range of int64_t is not 64. In such case, int64_t
is defined as long type and _INT64_IS_NOT_64BIT is defined.
>From C99 standard, long long type is wider or equal to long type.
To be on a safe side, I think it's better to define intmax_t
as long long type if it's available.

Thank you,
----
Mitsuru Chinen <[EMAIL PROTECTED]>



Index: snmplib/snmp_client.c
===================================================================
--- snmplib/snmp_client.c       (revision 16568)
+++ snmplib/snmp_client.c       (working copy)
@@ -807,16 +807,10 @@
                 }
             }
 #endif
-#if SIZEOF_LONG != SIZEOF_LONG_LONG
-#if defined (WIN32) && !defined (mingw32)
-            else if (vars->val_len == sizeof(__int64)){
-                const unsigned __int64   *val_ullong
-                    = (const unsigned __int64 *) value;
-#else
-                else if (vars->val_len == sizeof(long long)){
+#if defined(SIZEOF_LONG_LONG) && (SIZEOF_LONG != SIZEOF_LONG_LONG) && 
(SIZEOF_LONG_LONG != SIZEOF_INTMAX_T)
+            else if (vars->val_len == sizeof(long long)){
                 const unsigned long long   *val_ullong
                     = (const unsigned long long *) value;
-#endif
                 *(vars->val.integer) = (long) *val_ullong;
                 if (*(vars->val.integer) > 0xffffffff) {
                     snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
@@ -824,6 +818,17 @@
                 }
             }
 #endif
+#if SIZEOF_LONG != SIZEOF_INTMAX_T
+            else if (vars->val_len == sizeof(intmax_t)){
+                const uintmax_t *val_uintmax_t
+                    = (const uintmax_t *) value;
+                *(vars->val.integer) = (long) *val_uintmax_t;
+                if (*(vars->val.integer) > 0xffffffff) {
+                    snmp_log(LOG_ERR,"truncating integer value > 32 bits\n");
+                    *(vars->val.integer) &= 0xffffffff;
+                }
+            }
+#endif
 #if SIZEOF_SHORT != SIZEOF_INT
             else if (vars->val_len == sizeof(short)) {
                 if (ASN_INTEGER == vars->type) {
Index: include/net-snmp/types.h
===================================================================
--- include/net-snmp/types.h    (revision 16568)
+++ include/net-snmp/types.h    (working copy)
@@ -151,6 +151,7 @@
 #endif
 #ifdef INT64_T
 typedef INT64_T int64_t;
+#define HAVE_INT64_T 1
 #endif
 #endif /* !HAVE_INT64_T */
 
@@ -160,22 +161,32 @@
 #elif defined(INT64_T)
 typedef unsigned INT64_T uint64_t;
 #endif
+#define HAVE_UINT64_T 1
 #endif
 
 #ifndef HAVE_INTMAX_T
 #ifdef SIZEOF_LONG_LONG
 typedef long long intmax_t;
+#define SIZEOF_INTMAX_T SIZEOF_LONG_LONG
+#elif defined(HAVE_INT64_T) && !defined(_INT64_IS_NOT_64BIT)
+typedef int64_t   intmax_t;
+#define SIZEOF_INTMAX_T 8
 #else
 typedef long      intmax_t;
+#define SIZEOF_INTMAX_T SIZEOF_LONG
 #endif
+#define HAVE_INTMAX_T 1
 #endif
 
-#ifndef HAVE_INTMAX_T
+#ifndef HAVE_UINTMAX_T
 #ifdef SIZEOF_LONG_LONG
 typedef unsigned long long uintmax_t;
+#elif defined(HAVE_UINT64_T) && !defined(_INT64_IS_NOT_64BIT)
+typedef uint64_t           uintmax_t;
 #else
 typedef unsigned long      uintmax_t;
 #endif
+#define HAVE_UINTMAX_T 1
 #endif
 
 #ifndef HAVE_UINTPTR_T
Index: include/net-snmp/net-snmp-config.h.in
===================================================================
--- include/net-snmp/net-snmp-config.h.in       (revision 16568)
+++ include/net-snmp/net-snmp-config.h.in       (working copy)
@@ -1152,6 +1152,9 @@
 /* The size of a `int', as computed by sizeof. */
 #undef SIZEOF_INT
 
+/* The size of a `intmax_t', as computed by sizeof. */
+#undef SIZEOF_INTMAX_T
+
 /* The size of a `long', as computed by sizeof. */
 #undef SIZEOF_LONG
 
Index: configure.in
===================================================================
--- configure.in        (revision 16568)
+++ configure.in        (working copy)
@@ -1335,6 +1335,7 @@
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_SIZEOF(long long)
+AC_CHECK_SIZEOF(intmax_t)
 AC_CHECK_TYPES([int8_t,  uint8_t,  u_int8_t])
 AC_CHECK_TYPES([int16_t, uint16_t, u_int16_t])
 AC_CHECK_TYPES([int32_t, uint32_t, u_int32_t])
Index: win32/net-snmp/net-snmp-config.h.in
===================================================================
--- win32/net-snmp/net-snmp-config.h.in (revision 16568)
+++ win32/net-snmp/net-snmp-config.h.in (working copy)
@@ -933,9 +933,6 @@
 /* The size of a `long', as computed by sizeof. */
 #define SIZEOF_LONG 4
 
-/* The size of a `long long', as computed by sizeof. */
-#define SIZEOF_LONG_LONG 8
-
 /* The size of a `short', as computed by sizeof. */
 #define SIZEOF_SHORT 2
 
Index: win32/net-snmp/net-snmp-config.h
===================================================================
--- win32/net-snmp/net-snmp-config.h    (revision 16568)
+++ win32/net-snmp/net-snmp-config.h    (working copy)
@@ -933,9 +933,6 @@
 /* The size of a `long', as computed by sizeof. */
 #define SIZEOF_LONG 4
 
-/* The size of a `long long', as computed by sizeof. */
-#define SIZEOF_LONG_LONG 8
-
 /* The size of a `short', as computed by sizeof. */
 #define SIZEOF_SHORT 2
 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to