summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodger Combs <rodger.combs@gmail.com>2014-11-07 14:49:18 -0400
committerRodger Combs <rodger.combs@gmail.com>2014-11-08 10:39:28 -0600
commit0e8772a3bdca491230c90d3c9c7ab2ac5c18c2e7 (patch)
tree9464ee1d05593d4abbeb321d84aa42264d1ad6f0
parenta31ea5621a1fca4a4c927d11ece43c36b44b372c (diff)
downloadlibass-0e8772a3bdca491230c90d3c9c7ab2ac5c18c2e7.tar.bz2
libass-0e8772a3bdca491230c90d3c9c7ab2ac5c18c2e7.tar.xz
Check more allocations
Part of #146
-rw-r--r--libass/ass_bitmap.c16
-rw-r--r--libass/ass_render.c8
2 files changed, 23 insertions, 1 deletions
diff --git a/libass/ass_bitmap.c b/libass/ass_bitmap.c
index 9a98f5a..6de70f0 100644
--- a/libass/ass_bitmap.c
+++ b/libass/ass_bitmap.c
@@ -133,7 +133,13 @@ static Bitmap *alloc_bitmap_raw(int w, int h)
unsigned align = (w >= 32) ? 32 : ((w >= 16) ? 16 : 1);
unsigned s = ass_align(align, w);
bm = malloc(sizeof(Bitmap));
+ if (!bm)
+ return NULL;
bm->buffer = ass_aligned_alloc(align, s * h + 32);
+ if (!bm->buffer) {
+ free(bm);
+ return NULL;
+ }
bm->w = w;
bm->h = h;
bm->stride = s;
@@ -160,6 +166,8 @@ void ass_free_bitmap(Bitmap *bm)
Bitmap *copy_bitmap(const Bitmap *src)
{
Bitmap *dst = alloc_bitmap_raw(src->w, src->h);
+ if (!dst)
+ return NULL;
dst->left = src->left;
dst->top = src->top;
memcpy(dst->buffer, src->buffer, src->stride * src->h);
@@ -179,6 +187,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv,
if (rst->x_min >= rst->x_max || rst->y_min >= rst->y_max) {
Bitmap *bm = alloc_bitmap(2 * bord, 2 * bord);
+ if (!bm)
+ return NULL;
bm->left = bm->top = -bord;
return bm;
}
@@ -200,6 +210,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv,
int tile_w = (w + 2 * bord + mask) & ~mask;
int tile_h = (h + 2 * bord + mask) & ~mask;
Bitmap *bm = alloc_bitmap(tile_w, tile_h);
+ if (!bm)
+ return NULL;
bm->left = x_min - bord;
bm->top = -y_max - bord;
@@ -234,6 +246,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv,
FT_Outline_Get_CBox(outline, &bbox);
if (bbox.xMin >= bbox.xMax || bbox.yMin >= bbox.yMax) {
bm = alloc_bitmap(2 * bord, 2 * bord);
+ if (!bm)
+ return NULL;
bm->left = bm->top = -bord;
return bm;
}
@@ -259,6 +273,8 @@ Bitmap *outline_to_bitmap(ASS_Renderer *render_priv,
// allocate and set up bitmap
bm = alloc_bitmap(w + 2 * bord, h + 2 * bord);
+ if (!bm)
+ return NULL;
bm->left = bbox.xMin - bord;
bm->top = -bbox.yMax - bord;
bitmap.width = w;
diff --git a/libass/ass_render.c b/libass/ass_render.c
index d1a47ee..c1cf548 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -1883,7 +1883,8 @@ static void make_shadow_bitmap(CombinedBitmapInfo *info, ASS_Renderer *render_pr
} else
info->bm_s = copy_bitmap(info->bm);
- assert(info->bm_s);
+ if (!info->bm_s)
+ return;
// Works right even for negative offsets
// '>>' rounds toward negative infinity, '&' returns correct remainder
@@ -2557,11 +2558,15 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event,
int offset_y = (info->pos.y >> 6) - current_info->pos.y;
if(info->bm){
current_info->bm = copy_bitmap(info->bm);
+ if (!current_info->bm)
+ goto cleanup;
current_info->bm->left += offset_x;
current_info->bm->top += offset_y;
}
if(info->bm_o){
current_info->bm_o = copy_bitmap(info->bm_o);
+ if (!current_info->bm_o)
+ goto cleanup;
current_info->bm_o->left += offset_x;
current_info->bm_o->top += offset_y;
}
@@ -2593,6 +2598,7 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event,
}
}
}
+ cleanup:
info = info->next;
}
}