changeset 21359:3ebc6467c1a9

lib-compression: use LZ4_compress_default if can LZ4_compress is deprecated.
author Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
date Wed, 21 Dec 2016 07:53:52 +0200
parents 3c88a6868b52
children 063e6955617b
files configure.ac src/lib-compression/ostream-lz4.c
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sun Dec 18 12:03:10 2016 +0200
+++ b/configure.ac	Wed Dec 21 07:53:52 2016 +0200
@@ -2742,6 +2742,11 @@
 	AC_ERROR([Can't build with lz4 support: liblz4 not found])
       fi
     ])
+    AC_CHECK_LIB(lz4, LZ4_compress_default, [
+      AC_DEFINE(HAVE_LZ4_COMPRESS_DEFAULT,,
+	[Define if you have LZ4_compress_default])
+    ], [
+    ])
   ], [
     if test "$want_lz4" = "yes"; then
       AC_ERROR([Can't build with lz4 support: lz4.h not found])
--- a/src/lib-compression/ostream-lz4.c	Sun Dec 18 12:03:10 2016 +0200
+++ b/src/lib-compression/ostream-lz4.c	Wed Dec 21 07:53:52 2016 +0200
@@ -71,10 +71,27 @@
 	i_assert(zstream->outbuf_offset == 0);
 	i_assert(zstream->outbuf_used == 0);
 
+#if defined(HAVE_LZ4_COMPRESS_DEFAULT)
+	int max_dest_size = LZ4_compressBound(zstream->compressbuf_offset);
+	i_assert(max_dest_size >= 0);
+	if (max_dest_size == 0) {
+		io_stream_set_error(&zstream->ostream.iostream,
+			"lz4-compress: input size %u too large (> %u)",
+			zstream->compressbuf_offset, LZ4_MAX_INPUT_SIZE);
+		zstream->ostream.ostream.stream_errno = EINVAL;
+		return -1;
+	}
+	ret = LZ4_compress_default((void *)zstream->compressbuf,
+				   (void *)(zstream->outbuf +
+				            IOSTREAM_LZ4_CHUNK_PREFIX_LEN),
+				   zstream->compressbuf_offset,
+				   max_dest_size);
+#else
 	ret = LZ4_compress((void *)zstream->compressbuf,
 			   (void *)(zstream->outbuf +
 			            IOSTREAM_LZ4_CHUNK_PREFIX_LEN),
 			   zstream->compressbuf_offset);
+#endif /* defined(HAVE_LZ4_COMPRESS_DEFAULT) */
 	i_assert(ret > 0 && (unsigned int)ret <= sizeof(zstream->outbuf) -
 	         IOSTREAM_LZ4_CHUNK_PREFIX_LEN);
 	zstream->outbuf_used = IOSTREAM_LZ4_CHUNK_PREFIX_LEN + ret;