summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick 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)
commit35cfcd0fd74ebce66cd7bf12309b600d37c34623 (patch)
treee1c574f933a235b7b7f6d463fcf57d401d8a0ed8 /src
parentd178ff96b8ae52b834c2f627744f50fde0472f59 (diff)
text_render(): Duplicate string
Diffstat (limited to 'src')
-rw-r--r--src/text.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/text.c b/src/text.c
index 695d5aa..cb777e4 100644
--- a/src/text.c
+++ b/src/text.c
@@ -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 *