Fix multiple calls of `FT_Bitmap_Convert'. The documentation of `FT_Bitmap_Convert' says that multiple calls do proper reallocation of the target FT_Bitmap object. However, this failed for the sequence non-empty bitmap empty bitmap non-empty bitmap Reason was that `FT_Bitmap_Convert' only reallocated the bitmap buffer if it became too small; it didn't make the buffer smaller. For an empty bitmap following a non-empty one, only the buffer dimension got set to zero, without deallocation. If the next call was a non-empty buffer again, an assertion in `ft_mem_qrealloc' was triggered. * src/base/ftbitmap.c (FT_Bitmap_Convert): Always reallocate target buffer to the correct size. * docs/CHANGES: Document it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/ChangeLog b/ChangeLog
index 6ae91dd..c697729 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
2017-09-05 Werner Lemberg <wl@gnu.org>
+ Fix multiple calls of `FT_Bitmap_Convert'.
+
+ The documentation of `FT_Bitmap_Convert' says that multiple calls do
+ proper reallocation of the target FT_Bitmap object. However, this
+ failed for the sequence
+
+ non-empty bitmap
+ empty bitmap
+ non-empty bitmap
+
+ Reason was that `FT_Bitmap_Convert' only reallocated the bitmap
+ buffer if it became too small; it didn't make the buffer smaller.
+ For an empty bitmap following a non-empty one, only the buffer
+ dimension got set to zero, without deallocation. If the next call
+ was a non-empty buffer again, an assertion in `ft_mem_qrealloc' was
+ triggered.
+
+ * src/base/ftbitmap.c (FT_Bitmap_Convert): Always reallocate target
+ buffer to the correct size.
+
+ * docs/CHANGES: Document it.
+
+2017-09-05 Werner Lemberg <wl@gnu.org>
+
[bdf] Fix size and resolution handling.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Use `SIZE' values if
diff --git a/docs/CHANGES b/docs/CHANGES
index 7bb5fce..2bac995 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -54,6 +54,10 @@ CHANGES BETWEEN 2.8 and 2.8.1
missing. Previously, `SIZE' was completely ignored, and
FreeType used heuristic values instead.
+ - Multiple calls to `FT_Bitmap_Convert' do work now as advertised.
+ Previously, they failed with an assertion error if there was an
+ empty bitmap between non-empty ones.
+
======================================================================
diff --git a/src/base/ftbitmap.c b/src/base/ftbitmap.c
index ee50c2f..e567a04 100644
--- a/src/base/ftbitmap.c
+++ b/src/base/ftbitmap.c
@@ -534,8 +534,7 @@
(FT_ULong)target->rows > FT_ULONG_MAX / (FT_ULong)target_pitch )
return FT_THROW( Invalid_Argument );
- if ( target->rows * (FT_ULong)target_pitch > old_size &&
- FT_QREALLOC( target->buffer,
+ if ( FT_QREALLOC( target->buffer,
old_size, target->rows * (FT_UInt)target_pitch ) )
return error;