vtfontcvt: introduce xmalloc to abort on out-of-memory

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Ed Maste 2015-08-31 23:08:39 +00:00
parent 73457dc357
commit 2e268aa950
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=287336

View File

@ -96,6 +96,16 @@ usage(void)
exit(1); exit(1);
} }
static void *
xmalloc(size_t size)
{
void *m;
if ((m = malloc(size)) == NULL)
errx(1, "memory allocation failure");
return (m);
}
static int static int
add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx) add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx)
{ {
@ -104,7 +114,7 @@ add_mapping(struct glyph *gl, unsigned int c, unsigned int map_idx)
mapping_total++; mapping_total++;
mp = malloc(sizeof *mp); mp = xmalloc(sizeof *mp);
mp->m_char = c; mp->m_char = c;
mp->m_glyph = gl; mp->m_glyph = gl;
mp->m_length = 0; mp->m_length = 0;
@ -163,8 +173,8 @@ add_glyph(const uint8_t *bytes, unsigned int map_idx, int fallback)
} }
} }
gl = malloc(sizeof *gl); gl = xmalloc(sizeof *gl);
gl->g_data = malloc(wbytes * height); gl->g_data = xmalloc(wbytes * height);
memcpy(gl->g_data, bytes, wbytes * height); memcpy(gl->g_data, bytes, wbytes * height);
if (fallback) if (fallback)
TAILQ_INSERT_HEAD(&glyphs[map_idx], gl, g_list); TAILQ_INSERT_HEAD(&glyphs[map_idx], gl, g_list);