Handle malloc failure.

This commit is contained in:
Connor E 2019-01-20 13:55:25 +00:00
parent 445d948734
commit 83c543e051

View file

@ -91,6 +91,10 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
va_end(args); va_end(args);
char *buf = malloc(length); char *buf = malloc(length);
if (buf == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate memory");
return;
}
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buf, length, fmt, args); vsnprintf(buf, length, fmt, args);
va_end(args); va_end(args);
@ -114,6 +118,10 @@ void pango_printf(cairo_t *cairo, const char *font,
va_end(args); va_end(args);
char *buf = malloc(length); char *buf = malloc(length);
if (buf == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate memory");
return;
}
va_start(args, fmt); va_start(args, fmt);
vsnprintf(buf, length, fmt, args); vsnprintf(buf, length, fmt, args);
va_end(args); va_end(args);