diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-17 21:17:31 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-17 21:17:31 (EDT) |
commit | 35cfcd0fd74ebce66cd7bf12309b600d37c34623 (patch) | |
tree | e1c574f933a235b7b7f6d463fcf57d401d8a0ed8 | |
parent | d178ff96b8ae52b834c2f627744f50fde0472f59 (diff) |
text_render(): Duplicate string
-rw-r--r-- | src/text.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -22,6 +22,7 @@ #include "text.h" #include <stdlib.h> +#include <string.h> #include <png.h> @@ -97,14 +98,20 @@ text_get_height(struct text *text) void text_render(struct text *text, struct font *font, png_bytepp rows) { - const char *string; - size_t row; - size_t col; - png_color fg = {255, 255, 255}; - png_color bg = { 0, 0, 0}; - - string = text->string; + char *string_start; + char *string; + size_t row; + size_t col; + png_color fg = {255, 255, 255}; + png_color bg = { 0, 0, 0}; + + string_start = calloc(strlen(text->string) + 1, sizeof(*text->string)); + if (!string_start) { + return; + } + memcpy(string_start, text->string, strlen(text->string) + 1); + string = string_start; row = 0; col = 0; while (string && *string) { @@ -131,6 +138,8 @@ text_render(struct text *text, struct font *font, png_bytepp rows) for (; col < text->width; ++col) { font_render(font, &fg, &bg, ' ', rows, row, col); } + + free(string_start); } struct text * |