You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2014/03/04 17:53:52 UTC

svn commit: r1574132 - /subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Author: breser
Date: Tue Mar  4 16:53:52 2014
New Revision: 1574132

URL: http://svn.apache.org/r1574132
Log:
Fix compiler warnings about the size of membuffer cache entries.

Entries in the membuffer cache are limited to a maximum size of the maximum
value of an apr_uint32_t, since cache values larger than that would not be
efficient.  However, our APIs generally use apr_size_t for the size of data
in memory.  apr_size_t may be 64-bits wide on some platforms.

For the convenience of other developers the membuffer APIs take apr_size_t
values and the effort to ensure the cache entries are not larger than
apr_uint32_t is handled by the membuffer cache code itself.  It does this by
calculating the maximum cache entry value and comparing it against the size
of the incoming entry.  This means it is safe to cast the size to the
apr_uint32_t type it uses internally once this check has been completed.

* subversion/libsvn_subr/cache-membuffer.c
  (select_level): Cast to apr_uint32_t when setting dummy_entry.size.
  (membuffer_cache_set_internal, membuffer_cache_set_partial_internal):
    Cast to apr_uint32_t when setting entry->size.

Modified:
    subversion/trunk/subversion/libsvn_subr/cache-membuffer.c

Modified: subversion/trunk/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cache-membuffer.c?rev=1574132&r1=1574131&r2=1574132&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/trunk/subversion/libsvn_subr/cache-membuffer.c Tue Mar  4 16:53:52 2014
@@ -1855,7 +1855,7 @@ select_level(svn_membuffer_t *cache,
       /* Large and somewhat important items go into L2. */
       entry_t dummy_entry = { { 0 } };
       dummy_entry.priority = priority;
-      dummy_entry.size = size;
+      dummy_entry.size = (apr_uint32_t) size;
 
       return ensure_data_insertable_l2(cache, &dummy_entry)
            ? &cache->l2
@@ -1902,7 +1902,7 @@ membuffer_cache_set_internal(svn_membuff
        * negative value.
        */
       cache->data_used += (apr_uint64_t)size - entry->size;
-      entry->size = size;
+      entry->size = (apr_uint32_t) size;
       entry->priority = priority;
 
 #ifdef SVN_DEBUG_CACHE_MEMBUFFER
@@ -1931,7 +1931,7 @@ membuffer_cache_set_internal(svn_membuff
        * the serialized item's (future) position within data buffer.
        */
       entry = find_entry(cache, group_index, to_find, TRUE);
-      entry->size = size;
+      entry->size = (apr_uint32_t) size;
       entry->offset = level->current_data;
       entry->priority = priority;
 
@@ -2364,7 +2364,7 @@ membuffer_cache_set_partial_internal(svn
                   /* Write the new entry.
                    */
                   entry = find_entry(cache, group_index, to_find, TRUE);
-                  entry->size = size;
+                  entry->size = (apr_uint32_t) size;
                   entry->offset = cache->l1.current_data;
                   if (size)
                     memcpy(cache->data + entry->offset, data, size);