diff options
author | Philip Withnall <pwithnall@gnome.org> | 2024-04-12 20:08:37 +0100 |
---|---|---|
committer | Philip Withnall <pwithnall@gnome.org> | 2024-04-12 20:08:37 +0100 |
commit | 4cc93f9381e0eddd2cac1e92c0f36b29dcd8c1ce (patch) | |
tree | 669be52ca2e486d85f64251197092e23e20225de /src | |
parent | 405156637d32b87b3d58b3b2914f24fa44451009 (diff) |
xdgmimecache: Add assertion to silence static analysis false positive
After a lot of loop unwinding, during which I think it might have lost
its knowledge that `cache->buffer != NULL` (from a prior check on line
739), scan-build seems to think that there can be a `NULL` pointer
dereference of `cache->buffer` within `cache_magic_compare_to_data()`.
There can’t be. Add an assertion to try and help the analyser.
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/xdgmimecache.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/xdgmimecache.c b/src/xdgmimecache.c index 57d7e2b..bdcd6a6 100644 --- a/src/xdgmimecache.c +++ b/src/xdgmimecache.c @@ -245,10 +245,15 @@ cache_magic_compare_to_data (XdgMimeCache *cache, size_t len, int *prio) { - xdg_uint32_t priority = GET_UINT32 (cache->buffer, offset); - xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, offset + 4); - xdg_uint32_t n_matchlets = GET_UINT32 (cache->buffer, offset + 8); - xdg_uint32_t matchlet_offset = GET_UINT32 (cache->buffer, offset + 12); + xdg_uint32_t priority, mimetype_offset, n_matchlets, matchlet_offset; + + assert (cache->buffer != NULL); + + priority = GET_UINT32 (cache->buffer, offset); + mimetype_offset = GET_UINT32 (cache->buffer, offset + 4); + n_matchlets = GET_UINT32 (cache->buffer, offset + 8); + matchlet_offset = GET_UINT32 (cache->buffer, offset + 12); + if (OUT_OF_BOUNDS (matchlet_offset, n_matchlets, 32, cache->size)) return NULL; @@ -280,6 +285,8 @@ cache_magic_lookup_data (XdgMimeCache *cache, xdg_uint32_t j; + assert (cache->buffer != NULL); + *prio = 0; list_offset = GET_UINT32 (cache->buffer, 24); |