Jeff Trawick wrote:

APR_32BIT_TRUNC_CAST

defined only in private headers only so that

a) we don't add yet more symbols to API
b) we continually identify where our API is broken w.r.t. handling
quantities properly in a 64-bit world


I believe this addresses the issues

Allan
---------------------------------
Index: srclib/apr/include/apr.hnw
===================================================================
RCS file: /home/cvs/apr/include/apr.hnw,v
retrieving revision 1.49
diff -U3 -r1.49 apr.hnw
--- srclib/apr/include/apr.hnw  1 Oct 2004 19:24:03 -0000       1.49
+++ srclib/apr/include/apr.hnw  6 Oct 2004 18:48:51 -0000
@@ -330,7 +330,6 @@
 #define APR_UINT64_T_HEX_FMT     "llx"
 #define APR_TIME_T_FMT APR_INT64_T_FMT

-#define APR_DWORD_MAX 0xFFFFFFFFUL    /* 2^32*/
 /** @} */

 #ifdef __cplusplus
Index: srclib/apr/include/apr.hw
===================================================================
RCS file: /home/cvs/apr/include/apr.hw,v
retrieving revision 1.127
diff -U3 -r1.127 apr.hw
--- srclib/apr/include/apr.hw   1 Oct 2004 19:24:03 -0000       1.127
+++ srclib/apr/include/apr.hw   6 Oct 2004 18:48:51 -0000
@@ -342,8 +342,6 @@
 #define APR_SIZEOF_VOIDP   4
 #endif

-#define APR_DWORD_MAX 0xFFFFFFFFUL
-
 /* XXX These simply don't belong here, perhaps in apr_portable.h
  * based on some APR_HAVE_PID/GID/UID?
  */
Index: srclib/apr/include/arch/apr_private_common.h
===================================================================
RCS file: /home/cvs/apr/include/arch/apr_private_common.h,v
retrieving revision 1.2
diff -U3 -r1.2 apr_private_common.h
--- srclib/apr/include/arch/apr_private_common.h        13 Feb 2004 09:38:29 
-0000      1.2
+++ srclib/apr/include/arch/apr_private_common.h        6 Oct 2004 18:48:51 
-0000
@@ -33,4 +33,9 @@
                                           char separator,
                                           apr_pool_t *p);

+/* temporary defines to handle 64bit compile mismatches */
+#define APR_INT_TRUNC_CAST    int
+#define APR_UINT32_TRUNC_CAST apr_uint32_t
+#define APR_UINT32_MAX        0xFFFFFFFFUL
+
 #endif  /*APR_PRIVATE_COMMON_H*/
Index: srclib/apr/include/arch/netware/apr_private.h
===================================================================
RCS file: /home/cvs/apr/include/arch/netware/apr_private.h,v
retrieving revision 1.25
diff -U3 -r1.25 apr_private.h
--- srclib/apr/include/arch/netware/apr_private.h       6 Jul 2004 22:40:49 
-0000       1.25
+++ srclib/apr/include/arch/netware/apr_private.h       6 Oct 2004 18:48:51 
-0000
@@ -172,6 +172,9 @@
 #define APR_OFF_T_STRFN       strtol
 #endif

+/* used to check DWORD overflow for 64bit compiles */
+#define APR_DWORD_MAX 0xFFFFFFFFUL
+
 /*
  * Include common private declarations.
  */
Index: srclib/apr/include/arch/win32/apr_private.h
===================================================================
RCS file: /home/cvs/apr/include/arch/win32/apr_private.h,v
retrieving revision 1.38
diff -U3 -r1.38 apr_private.h
--- srclib/apr/include/arch/win32/apr_private.h 4 Jun 2004 23:26:02 -0000       
1.38
+++ srclib/apr/include/arch/win32/apr_private.h 6 Oct 2004 18:48:52 -0000
@@ -158,6 +158,9 @@
 #define APR_OFF_T_STRFN         strtoi
 #endif

+/* used to check for DWORD overflow in 64bit compiles */
+#define APR_DWORD_MAX 0xFFFFFFFFUL
+
 /*
  * Include common private declarations.
  */
Index: srclib/apr/memory/unix/apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.206
diff -U3 -r1.206 apr_pools.c
--- srclib/apr/memory/unix/apr_pools.c  17 Jun 2004 14:13:58 -0000      1.206
+++ srclib/apr/memory/unix/apr_pools.c  6 Oct 2004 18:48:53 -0000
@@ -139,9 +139,10 @@
 }

 APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator,
-                                             apr_size_t size)
+                                             apr_size_t in_size)
 {
     apr_uint32_t max_free_index;
+    apr_uint32_t size = (APR_UINT32_TRUNC_CAST)in_size;

 #if APR_HAS_THREADS
     apr_thread_mutex_t *mutex;
@@ -168,7 +169,8 @@
 apr_memnode_t *allocator_alloc(apr_allocator_t *allocator, apr_size_t size)
 {
     apr_memnode_t *node, **ref;
-    apr_uint32_t i, index, max_index;
+    apr_uint32_t max_index;
+    apr_size_t i, index;

     /* Round up the block size to the next boundary, but always
      * allocate at least a certain size (MIN_ALLOC).
@@ -181,6 +183,10 @@
      * dividing its size by the boundary size
      */
     index = (size >> BOUNDARY_INDEX) - 1;
+
+    if (index > APR_UINT32_MAX) {
+        return NULL;
+    }

     /* First see if there are any nodes in the area we know
      * our node will fit into.
@@ -293,7 +299,7 @@
         return NULL;

     node->next = NULL;
-    node->index = index;
+    node->index = (APR_UINT32_TRUNC_CAST)index;
     node->first_avail = (char *)node + APR_MEMNODE_T_SIZE;
     node->endp = (char *)node + size;

@@ -582,7 +588,7 @@
 {
     apr_memnode_t *active, *node;
     void *mem;
-    apr_uint32_t free_index;
+    apr_size_t free_index;

     size = APR_ALIGN_DEFAULT(size);
     active = pool->active;
@@ -620,7 +626,7 @@
     free_index = (APR_ALIGN(active->endp - active->first_avail + 1,
                             BOUNDARY_SIZE) - BOUNDARY_SIZE) >> BOUNDARY_INDEX;

-    active->free_index = free_index;
+    active->free_index = (APR_UINT32_TRUNC_CAST)free_index;
     node = active->next;
     if (free_index >= node->free_index)
         return mem;
@@ -877,7 +883,7 @@
     apr_size_t cur_len, size;
     char *strp;
     apr_pool_t *pool;
-    apr_uint32_t free_index;
+    apr_size_t free_index;

     pool = ps->pool;
     active = ps->node;
@@ -907,7 +913,7 @@
         free_index = (APR_ALIGN(active->endp - active->first_avail + 1,
                                 BOUNDARY_SIZE) - BOUNDARY_SIZE) >> 
BOUNDARY_INDEX;

-        active->free_index = free_index;
+        active->free_index = (APR_UINT32_TRUNC_CAST)free_index;
         node = active->next;
         if (free_index < node->free_index) {
             do {
@@ -948,7 +954,7 @@
     char *strp;
     apr_size_t size;
     apr_memnode_t *active, *node;
-    apr_uint32_t free_index;
+    apr_size_t free_index;

     ps.node = active = pool->active;
     ps.pool = pool;
@@ -1008,7 +1014,7 @@
     free_index = (APR_ALIGN(active->endp - active->first_avail + 1,
                             BOUNDARY_SIZE) - BOUNDARY_SIZE) >> BOUNDARY_INDEX;

-    active->free_index = free_index;
+    active->free_index = (APR_UINT32_TRUNC_CAST)free_index;
     node = active->next;

     if (free_index >= node->free_index)



Reply via email to