Mesa (master): util/disk_cache: fix size subtraction on 32bit

Timothy Arceri tarceri at kemper.freedesktop.org
Thu Mar 9 09:26:47 UTC 2017


Module: Mesa
Branch: master
Commit: 61bbb25a080e48a8ca897ba7f6e73cc6a8e9b5b8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=61bbb25a080e48a8ca897ba7f6e73cc6a8e9b5b8

Author: Grazvydas Ignotas <notasas at gmail.com>
Date:   Thu Mar  9 02:54:53 2017 +0200

util/disk_cache: fix size subtraction on 32bit

Negating size_t on 32bit produces a 32bit result. This was effectively
adding values close to UINT_MAX to the cache size (the files are usually
small) instead of intended subtraction.
Fixes 'make check' disk_cache failures on 32bit.

Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/util/disk_cache.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 5470688..facdcec 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -603,7 +603,7 @@ evict_random_item(struct disk_cache *cache)
    free(dir_path);
 
    if (size) {
-      p_atomic_add(cache->size, - size);
+      p_atomic_add(cache->size, - (uint64_t)size);
       return;
    }
 
@@ -624,7 +624,7 @@ evict_random_item(struct disk_cache *cache)
    free(dir_path);
 
    if (size)
-      p_atomic_add(cache->size, - size);
+      p_atomic_add(cache->size, - (uint64_t)size);
 }
 
 void
@@ -646,7 +646,7 @@ disk_cache_remove(struct disk_cache *cache, const cache_key key)
    free(filename);
 
    if (sb.st_size)
-      p_atomic_add(cache->size, - sb.st_size);
+      p_atomic_add(cache->size, - (uint64_t)sb.st_size);
 }
 
 /* From the zlib docs:




More information about the mesa-commit mailing list