diff options
author | Robin Watts <robin.watts@artifex.com> | 2012-04-05 18:01:54 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2012-04-05 18:26:34 +0100 |
commit | e7b13e1de4b29f36ed536bb863e5d81768550490 (patch) | |
tree | 82b9645887a4eb1223f49e76f4f8872204019fa0 /pdf/pdf_metrics.c | |
parent | ff55e72b741b955bbd0e23bd9d724c6682a181ac (diff) | |
download | mupdf-e7b13e1de4b29f36ed536bb863e5d81768550490.tar.xz |
Fix potential problems on malloc failure.
Don't reset the size of arrays until we have successfully resized them.
Diffstat (limited to 'pdf/pdf_metrics.c')
-rw-r--r-- | pdf/pdf_metrics.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/pdf/pdf_metrics.c b/pdf/pdf_metrics.c index 888757c0..7c09ad4e 100644 --- a/pdf/pdf_metrics.c +++ b/pdf/pdf_metrics.c @@ -25,8 +25,9 @@ pdf_add_hmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int w) { if (font->hmtx_len + 1 >= font->hmtx_cap) { - font->hmtx_cap = font->hmtx_cap + 16; - font->hmtx = fz_resize_array(ctx, font->hmtx, font->hmtx_cap, sizeof(pdf_hmtx)); + int new_cap = font->hmtx_cap + 16; + font->hmtx = fz_resize_array(ctx, font->hmtx, new_cap, sizeof(pdf_hmtx)); + font->hmtx_cap = new_cap; } font->hmtx[font->hmtx_len].lo = lo; @@ -40,8 +41,9 @@ pdf_add_vmtx(fz_context *ctx, pdf_font_desc *font, int lo, int hi, int x, int y, { if (font->vmtx_len + 1 >= font->vmtx_cap) { - font->vmtx_cap = font->vmtx_cap + 16; - font->vmtx = fz_resize_array(ctx, font->vmtx, font->vmtx_cap, sizeof(pdf_vmtx)); + int new_cap = font->vmtx_cap + 16; + font->vmtx = fz_resize_array(ctx, font->vmtx, new_cap, sizeof(pdf_vmtx)); + font->vmtx_cap = new_cap; } font->vmtx[font->vmtx_len].lo = lo; |