gfileutils: Add an assertion to help static analysis

This assertion basically mirrors the existing `buffer_size >= 2`
assertion (one implies the other), but scan-build doesn’t seem to be
able to work that out — so give it some help.

Fixes:
```
../../../glib/gfileutils.c: In function ‘g_get_current_dir’:
../../../glib/gfileutils.c:2995:17: warning: potential null pointer dereference [-Wnull-dereference]
 2995 |       buffer[1] = 0;
      |       ~~~~~~~~~~^~~
../../../glib/gfileutils.c:2994:17: warning: potential null pointer dereference [-Wnull-dereference]
 2994 |       buffer[0] = G_DIR_SEPARATOR;
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2024-12-31 12:45:42 +00:00
parent 68388cf7f7
commit 1ab1cd6ba4
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -2991,6 +2991,7 @@ g_get_current_dir (void)
{
/* Fallback return value */
g_assert (buffer_size >= 2);
g_assert (buffer != NULL);
buffer[0] = G_DIR_SEPARATOR;
buffer[1] = 0;
}