[1/2] oleaut32: Pass size without terminating null to get_cache_entry.

Sebastian Lackner sebastian at fds-team.de
Thu Dec 24 23:37:44 CST 2015


Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

This patch is basically a noop, but should make the code more readable.
The BSTR cache only works properly, when get_cache_entry() correctly
groups all memory allocations of the same size into one bucket. In the
current implementation bstr_alloc_size() takes the size without
terminating NULL character, but get_cache_entry() expects the size with
terminating NULL character, which might be confusing.

 dlls/oleaut32/oleaut.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/dlls/oleaut32/oleaut.c b/dlls/oleaut32/oleaut.c
index 0352215..75f9cb4 100644
--- a/dlls/oleaut32/oleaut.c
+++ b/dlls/oleaut32/oleaut.c
@@ -119,7 +119,7 @@ static inline bstr_t *bstr_from_str(BSTR str)
 
 static inline bstr_cache_entry_t *get_cache_entry(size_t size)
 {
-    unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size-1])/BUCKET_SIZE;
+    unsigned cache_idx = FIELD_OFFSET(bstr_t, u.ptr[size+sizeof(WCHAR)-1])/BUCKET_SIZE;
     return bstr_cache_enabled && cache_idx < sizeof(bstr_cache)/sizeof(*bstr_cache)
         ? bstr_cache + cache_idx
         : NULL;
@@ -127,14 +127,14 @@ static inline bstr_cache_entry_t *get_cache_entry(size_t size)
 
 static bstr_t *alloc_bstr(size_t size)
 {
-    bstr_cache_entry_t *cache_entry = get_cache_entry(size+sizeof(WCHAR));
+    bstr_cache_entry_t *cache_entry = get_cache_entry(size);
     bstr_t *ret;
 
     if(cache_entry) {
         EnterCriticalSection(&cs_bstr_cache);
 
         if(!cache_entry->cnt) {
-            cache_entry = get_cache_entry(size+sizeof(WCHAR)+BUCKET_SIZE);
+            cache_entry = get_cache_entry(size+BUCKET_SIZE);
             if(cache_entry && !cache_entry->cnt)
                 cache_entry = NULL;
         }
@@ -258,7 +258,7 @@ void WINAPI SysFreeString(BSTR str)
         return;
 
     bstr = bstr_from_str(str);
-    cache_entry = get_cache_entry(bstr->size+sizeof(WCHAR));
+    cache_entry = get_cache_entry(bstr->size);
     if(cache_entry) {
         unsigned i;
 
-- 
2.6.4



More information about the wine-patches mailing list