From 50ab67703615834810c4fc55c8ef584d4e66a44e Mon Sep 17 00:00:00 2001 From: c-spencer Date: Thu, 9 Aug 2012 19:32:56 +0100 Subject: [PATCH] Use strndup for duplicating fontFamily strings. --- src/CanvasRenderingContext2d.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index dabb479..7a820e3 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -53,7 +53,7 @@ enum { void state_assign_fontFamily(canvas_state_t *state, const char *str) { free(state->fontFamily); - state->fontFamily = (char *) malloc(strlen(str) + 1); + state->fontFamily = strndup(str, 100); strcpy(state->fontFamily, str); } @@ -203,7 +203,7 @@ Context2d::saveState() { states[++stateno] = (canvas_state_t *) malloc(sizeof(canvas_state_t)); memcpy(states[stateno], state, sizeof(canvas_state_t)); #if HAVE_PANGO - states[stateno]->fontFamily = (char *) malloc(strlen(state->fontFamily) + 1); + states[stateno]->fontFamily = strndup(state->fontFamily, 100); strcpy(states[stateno]->fontFamily, state->fontFamily); #endif state = states[stateno];