From d434bfa86fba13bfe65802a35431893f34e20ea6 Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Mon, 19 Aug 2013 22:49:03 +0800 Subject: [PATCH] Better tun the use of open_memstream to safe versions of glibc --- libs/spandsp/src/t30.c | 2 +- libs/spandsp/src/t42.c | 11 ++++++++--- libs/spandsp/src/t4_tx.c | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/libs/spandsp/src/t30.c b/libs/spandsp/src/t30.c index 1d3555a97d..d629d79087 100644 --- a/libs/spandsp/src/t30.c +++ b/libs/spandsp/src/t30.c @@ -2589,7 +2589,7 @@ static int start_sending_document(t30_state_t *s) t30_set_status(s, T30_ERR_NORESSUPPORT); break; default: - span_log(&s->logging, SPAN_LOG_WARNING, "Cannot negotiate an image format\n"); + span_log(&s->logging, SPAN_LOG_WARNING, "Cannot negotiate an image mode\n"); t30_set_status(s, T30_ERR_BADTIFF); break; } diff --git a/libs/spandsp/src/t42.c b/libs/spandsp/src/t42.c index 2fa943cb9c..fc90ddba63 100644 --- a/libs/spandsp/src/t42.c +++ b/libs/spandsp/src/t42.c @@ -72,6 +72,11 @@ #include "spandsp/private/t85.h" #include "spandsp/private/t42.h" +/* The open_memstream() and fmemopen() in older versions of glibc seems quirky */ +#if defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12)) +#undef OPEN_MEMSTREAM +#endif + #define T42_USE_LUTS #include "t42_t43_local.h" @@ -1209,7 +1214,7 @@ SPAN_DECLARE(void) t42_decode_rx_status(t42_decode_state_t *s, int status) { if (t42_itulab_jpeg_to_srgb(s)) span_log(&s->logging, SPAN_LOG_FLOW, "Failed to convert from ITULAB.\n"); - s->end_of_data = 1; + s->end_of_data = true; } break; default: @@ -1229,7 +1234,7 @@ SPAN_DECLARE(int) t42_decode_put(t42_decode_state_t *s, const uint8_t data[], si { if (t42_itulab_jpeg_to_srgb(s)) span_log(&s->logging, SPAN_LOG_FLOW, "Failed to convert from ITULAB.\n"); - s->end_of_data = 1; + s->end_of_data = true; } return T4_DECODE_OK; } @@ -1319,7 +1324,7 @@ set_lab_illuminant(&s->lab, 95.047f, 100.000f, 108.883f); set_lab_gamut(&s->lab, 0, 100, -85, 85, -75, 125, false); } - s->end_of_data = 0; + s->end_of_data = false; s->compressed_image_size = 0; s->error_message[0] = '\0'; diff --git a/libs/spandsp/src/t4_tx.c b/libs/spandsp/src/t4_tx.c index f349a136c5..639ddc93dd 100644 --- a/libs/spandsp/src/t4_tx.c +++ b/libs/spandsp/src/t4_tx.c @@ -1863,7 +1863,7 @@ SPAN_DECLARE(int) t4_tx_set_tx_image_format(t4_tx_state_t *s, s->metadata.image_type = T4_IMAGE_TYPE_BILEVEL; } /* Squashing to a bi-level image is possible */ - span_log(&s->logging, SPAN_LOG_FLOW, "The image will be flattened to %d\n", s->metadata.image_type); + span_log(&s->logging, SPAN_LOG_FLOW, "The image may be flattened to %d\n", s->metadata.image_type); } } @@ -2022,8 +2022,18 @@ SPAN_DECLARE(int) t4_tx_set_tx_image_format(t4_tx_state_t *s, if (s->metadata.image_type != s->tiff.image_type || s->metadata.image_width != s->tiff.image_width) { - if (image_translate_init(&s->translator, s->metadata.image_type, s->metadata.image_width, -1, s->tiff.image_type, s->tiff.image_width, s->tiff.image_length, translate_row_read2, s) == NULL) + if (image_translate_init(&s->translator, + s->metadata.image_type, + s->metadata.image_width, + -1, + s->tiff.image_type, + s->tiff.image_width, + s->tiff.image_length, + translate_row_read2, + s) == NULL) + { return T4_IMAGE_FORMAT_INCOMPATIBLE; + } s->metadata.image_length = image_translate_get_output_length(&s->translator); }