mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-24 04:45:41 +02:00
particle/string: mbstowcs() may fail. When it does, don't crash
This commit is contained in:
parent
732470e5a6
commit
2d343755ce
1 changed files with 15 additions and 11 deletions
|
@ -45,12 +45,15 @@ begin_expose(struct exposable *exposable)
|
||||||
font->name, font->fextents.ascent,
|
font->name, font->fextents.ascent,
|
||||||
font->fextents.descent, font->fextents.height);
|
font->fextents.descent, font->fextents.height);
|
||||||
|
|
||||||
|
e->glyphs = NULL;
|
||||||
|
e->num_glyphs = 0;
|
||||||
|
|
||||||
size_t chars = mbstowcs(NULL, e->text, 0);
|
size_t chars = mbstowcs(NULL, e->text, 0);
|
||||||
|
if (chars != (size_t)-1) {
|
||||||
wchar_t wtext[chars + 1];
|
wchar_t wtext[chars + 1];
|
||||||
mbstowcs(wtext, e->text, chars + 1);
|
mbstowcs(wtext, e->text, chars + 1);
|
||||||
|
|
||||||
e->glyphs = malloc(chars * sizeof(e->glyphs[0]));
|
e->glyphs = malloc(chars * sizeof(e->glyphs[0]));
|
||||||
e->num_glyphs = 0;
|
|
||||||
|
|
||||||
/* Convert text to glyph masks/images. */
|
/* Convert text to glyph masks/images. */
|
||||||
for (size_t i = 0; i < chars; i++) {
|
for (size_t i = 0; i < chars; i++) {
|
||||||
|
@ -59,6 +62,7 @@ begin_expose(struct exposable *exposable)
|
||||||
continue;
|
continue;
|
||||||
e->glyphs[e->num_glyphs++] = glyph;
|
e->glyphs[e->num_glyphs++] = glyph;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exposable->width = exposable->particle->left_margin +
|
exposable->width = exposable->particle->left_margin +
|
||||||
exposable->particle->right_margin;
|
exposable->particle->right_margin;
|
||||||
|
|
Loading…
Add table
Reference in a new issue