aboutsummaryrefslogtreecommitdiff
path: root/common/pango.c
diff options
context:
space:
mode:
authorConnor E <38229097+c-edw@users.noreply.github.com>2019-01-16 09:57:51 +0000
committeremersion <contact@emersion.fr>2019-01-16 13:02:26 +0100
commitde6f5b345380e80b4d59ebc569697683af064424 (patch)
tree2ba6738b30a3cdcbceb0d8307424217fca448252 /common/pango.c
parentaa9d7d8ca19f4489839f765ad7f190e8141bd001 (diff)
Use static arrays where possible.
Diffstat (limited to 'common/pango.c')
-rw-r--r--common/pango.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/common/pango.c b/common/pango.c
index 18b92e9d..db8413f7 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -10,8 +10,9 @@
#include "log.h"
#include "stringop.h"
+#define MAX_CHARS 16384
+
static const char overflow[] = "[buffer overflow]";
-static const int max_chars = 16384;
size_t escape_markup_text(const char *src, char *dest) {
size_t length = 0;
@@ -87,11 +88,11 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
int *baseline, double scale, bool markup, const char *fmt, ...) {
- char *buf = malloc(sizeof(char) * max_chars);
+ char buf[MAX_CHARS];
va_list args;
va_start(args, fmt);
- if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) {
+ if (vsnprintf(buf, sizeof(buf), fmt, args) >= MAX_CHARS) {
strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow);
}
va_end(args);
@@ -103,17 +104,15 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
*baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
}
g_object_unref(layout);
-
- free(buf);
}
void pango_printf(cairo_t *cairo, const char *font,
double scale, bool markup, const char *fmt, ...) {
- char *buf = malloc(sizeof(char) * max_chars);
+ char buf[MAX_CHARS];
va_list args;
va_start(args, fmt);
- if (vsnprintf(buf, sizeof(char) * max_chars, fmt, args) >= max_chars) {
+ if (vsnprintf(buf, sizeof(buf), fmt, args) >= MAX_CHARS) {
strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow);
}
va_end(args);
@@ -126,6 +125,4 @@ void pango_printf(cairo_t *cairo, const char *font,
pango_cairo_update_layout(cairo, layout);
pango_cairo_show_layout(cairo, layout);
g_object_unref(layout);
-
- free(buf);
}