mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-07 17:00:16 +01:00
util: add a safe version of strlen
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1052>
This commit is contained in:
parent
da6059b2fe
commit
1790171c76
2 changed files with 10 additions and 1 deletions
|
|
@ -1314,7 +1314,7 @@ match_fill_uniq(struct match *m,
|
|||
str++;
|
||||
|
||||
m->uniq = safe_strdup(str);
|
||||
slen = strlen(m->uniq);
|
||||
slen = safe_strlen(m->uniq);
|
||||
if (slen > 1 &&
|
||||
m->uniq[slen - 1] == '"')
|
||||
m->uniq[slen - 1] = '\0';
|
||||
|
|
|
|||
|
|
@ -99,6 +99,15 @@ safe_strdup(const char *str)
|
|||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* NULL-safe version of strlen
|
||||
*/
|
||||
static inline size_t
|
||||
safe_strlen(const char *str)
|
||||
{
|
||||
return str ? strlen(str) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple wrapper for asprintf that ensures the passed in-pointer is set
|
||||
* to NULL upon error.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue