xdgmime: 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
765), 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.

Upstreamed as
https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/38.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
This commit is contained in:
Philip Withnall 2024-04-09 16:30:23 +01:00
parent c4affcb4f0
commit 3e68debb13
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -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);