diff options
author | Connor E <38229097+c-edw@users.noreply.github.com> | 2018-10-16 19:05:41 +0100 |
---|---|---|
committer | Connor E <38229097+c-edw@users.noreply.github.com> | 2018-10-16 20:20:45 +0100 |
commit | cfc533aa9cadb0a382ac4ddfc8c011657febb2da (patch) | |
tree | 49d10e53cd1e1da6b8eb075ab8000bbd9a1bdf5e /common | |
parent | 113751ea48b9ffa537c357373913ca9caecb68e0 (diff) |
Truncate message, append buffer overflow message if too long.
Increase buffer size, remove macros.
Make variables lowercase.
Some more feedback.
Diffstat (limited to 'common')
-rw-r--r-- | common/pango.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/common/pango.c b/common/pango.c index ba74692e..f0b8db66 100644 --- a/common/pango.c +++ b/common/pango.c @@ -10,6 +10,9 @@ #include "log.h" #include "stringop.h" +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; if (dest) { @@ -84,12 +87,12 @@ 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, ...) { - static char buf[2048]; + char buf[max_chars]; va_list args; va_start(args, fmt); - if (vsnprintf(buf, 2048, fmt, args) >= 2048) { - strcpy(buf, "[buffer overflow]"); + if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { + strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); } va_end(args); @@ -104,12 +107,12 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, void pango_printf(cairo_t *cairo, const char *font, double scale, bool markup, const char *fmt, ...) { - static char buf[2048]; + char buf[max_chars]; va_list args; va_start(args, fmt); - if (vsnprintf(buf, 2048, fmt, args) >= 2048) { - strcpy(buf, "[buffer overflow]"); + if (vsnprintf(buf, sizeof(buf), fmt, args) >= max_chars) { + strcpy(&buf[sizeof(buf) - sizeof(overflow)], overflow); } va_end(args); |