summaryrefslogtreecommitdiffstats
path: root/libass/ass_drawing.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-17 21:24:52 +0100
committerwm4 <wm4@nowhere>2014-11-17 21:24:52 +0100
commit1b2795913a99e5df799b272528dcf57e8d6fce3f (patch)
treea990abb094d346ecab018a01aa3e2476db41c917 /libass/ass_drawing.c
parent2f9467cfd2574af44f97ee89b460c410a5a3c85a (diff)
downloadlibass-1b2795913a99e5df799b272528dcf57e8d6fce3f.tar.bz2
libass-1b2795913a99e5df799b272528dcf57e8d6fce3f.tar.xz
More malloc checking
Use strndup() instead of malloc+copy. Make all code deal with the possibility that ASS_Drawing.text can be NULL (which can happen on allocation failure). Skip fix_collisions() on malloc failure - the lines will overlap, but at least libass won't crash.
Diffstat (limited to 'libass/ass_drawing.c')
-rw-r--r--libass/ass_drawing.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/libass/ass_drawing.c b/libass/ass_drawing.c
index cc847af..88ec89c 100644
--- a/libass/ass_drawing.c
+++ b/libass/ass_drawing.c
@@ -146,7 +146,7 @@ static ASS_DrawingToken *drawing_tokenize(char *str)
ASS_DrawingToken *root = NULL, *tail = NULL, *spline_start = NULL;
- while (*p) {
+ while (p && *p) {
if (*p == 'c' && spline_start) {
// Close b-splines: add the first three points of the b-spline
// back to the end
@@ -379,9 +379,7 @@ void ass_drawing_free(ASS_Drawing* drawing)
void ass_drawing_set_text(ASS_Drawing* drawing, char *str, size_t len)
{
free(drawing->text);
- drawing->text = malloc(len + 1);
- memcpy(drawing->text, str, len);
- drawing->text[len] = 0;
+ drawing->text = strndup(str, len);
}
/*
@@ -390,6 +388,8 @@ void ass_drawing_set_text(ASS_Drawing* drawing, char *str, size_t len)
*/
void ass_drawing_hash(ASS_Drawing* drawing)
{
+ if (!drawing->text)
+ return;
drawing->hash = fnv_32a_str(drawing->text, FNV1_32A_INIT);
}