libsysprof-analyze: add CString helper

This checks, up to the end of the frame, that we have a valid \0 for the
CString before passing it back to the caller. Otherwise, NULL is returned
for a corrupt/invalid CString within the frame.
This commit is contained in:
Christian Hergert
2023-04-27 16:59:41 -07:00
parent ca83cd6b40
commit 1182b65c07

View File

@ -80,4 +80,19 @@ SysprofDocumentFrame *_sysprof_document_frame_new (GMappedFile *ma
(SYSPROF_DOCUMENT_FRAME_NEEDS_SWAP(obj) ? GINT64_TO_BE(val) : (val))
#endif
static inline const char *
SYSPROF_DOCUMENT_FRAME_CSTRING (SysprofDocumentFrame *self,
const char *str)
{
const char *endptr = (const char *)self->frame + self->frame_len;
for (const char *c = str; c < endptr; c++)
{
if (*c == 0)
return str;
}
return NULL;
}
G_END_DECLS