From 35cfcd0fd74ebce66cd7bf12309b600d37c34623 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 17 Jul 2019 21:17:31 -0400 Subject: text_render(): Duplicate string --- (limited to 'src') 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 +#include #include @@ -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 * -- cgit v0.9.1