OSDN Git Service

u_cache: fix dereference before NULL check
authorDave Airlie <airlied@gmail.com>
Fri, 30 Nov 2012 08:48:47 +0000 (18:48 +1000)
committerDave Airlie <airlied@gmail.com>
Tue, 4 Dec 2012 07:55:52 +0000 (17:55 +1000)
src/gallium/auxiliary/util/u_cache.c

index df08ec3..26aab2b 100644 (file)
@@ -183,12 +183,12 @@ util_cache_set(struct util_cache *cache,
                void *value)
 {
    struct util_cache_entry *entry;
-   uint32_t hash = cache->hash(key);
+   uint32_t hash;
 
    assert(cache);
    if (!cache)
       return;
-
+   hash = cache->hash(key);
    entry = util_cache_entry_get(cache, hash, key);
    if (!entry)
       entry = cache->lru.prev;
@@ -218,12 +218,12 @@ util_cache_get(struct util_cache *cache,
                const void *key)
 {
    struct util_cache_entry *entry;
-   uint32_t hash = cache->hash(key);
+   uint32_t hash;
 
    assert(cache);
    if (!cache)
       return NULL;
-
+   hash = cache->hash(key);
    entry = util_cache_entry_get(cache, hash, key);
    if (!entry)
       return NULL;