mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-02 17:26:17 +01:00
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:
parent
c4affcb4f0
commit
3e68debb13
@ -245,10 +245,15 @@ cache_magic_compare_to_data (XdgMimeCache *cache,
|
|||||||
size_t len,
|
size_t len,
|
||||||
int *prio)
|
int *prio)
|
||||||
{
|
{
|
||||||
xdg_uint32_t priority = GET_UINT32 (cache->buffer, offset);
|
xdg_uint32_t priority, mimetype_offset, n_matchlets, matchlet_offset;
|
||||||
xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, offset + 4);
|
|
||||||
xdg_uint32_t n_matchlets = GET_UINT32 (cache->buffer, offset + 8);
|
assert (cache->buffer != NULL);
|
||||||
xdg_uint32_t matchlet_offset = GET_UINT32 (cache->buffer, offset + 12);
|
|
||||||
|
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))
|
if (OUT_OF_BOUNDS (matchlet_offset, n_matchlets, 32, cache->size))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -280,6 +285,8 @@ cache_magic_lookup_data (XdgMimeCache *cache,
|
|||||||
|
|
||||||
xdg_uint32_t j;
|
xdg_uint32_t j;
|
||||||
|
|
||||||
|
assert (cache->buffer != NULL);
|
||||||
|
|
||||||
*prio = 0;
|
*prio = 0;
|
||||||
|
|
||||||
list_offset = GET_UINT32 (cache->buffer, 24);
|
list_offset = GET_UINT32 (cache->buffer, 24);
|
||||||
|
Loading…
Reference in New Issue
Block a user