mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-16 22:05:21 -05:00
term: set_app_id() + set_window_title(): only allow printable characters
This commit is contained in:
parent
9a1b59adae
commit
d523e7a676
4 changed files with 19 additions and 6 deletions
17
misc.c
17
misc.c
|
|
@ -44,8 +44,19 @@ timespec_sub(const struct timespec *a, const struct timespec *b,
|
|||
}
|
||||
|
||||
bool
|
||||
is_valid_utf8(const char *value)
|
||||
is_valid_utf8_and_printable(const char *value)
|
||||
{
|
||||
return value != NULL &&
|
||||
mbsntoc32(NULL, value, strlen(value), 0) != (size_t)-1;
|
||||
char32_t *wide = ambstoc32(value);
|
||||
if (wide == NULL)
|
||||
return false;
|
||||
|
||||
for (const char32_t *c = wide; *c != U'\0'; c++) {
|
||||
if (!isc32print(*c)) {
|
||||
free(wide);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
free(wide);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue