From 8d05ae5257dba8e077063d0023bd5cdeabf463ac Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Fri, 9 Jul 2021 16:57:55 +0200 Subject: [PATCH] fix arginfo and build warnings --- utils.c | 2 +- utils.h | 2 +- xz.c | 23 +++++++++++++---------- xz_fopen_wrapper.c | 11 ++++++----- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/utils.c b/utils.c index 45884a3..fd94186 100644 --- a/utils.c +++ b/utils.c @@ -20,7 +20,7 @@ #include "php.h" -void *memmerge(char *ptr1, char *ptr2, size_t len1, size_t len2) /* {{{ */ +void *memmerge(void *ptr1, void *ptr2, size_t len1, size_t len2) /* {{{ */ { if ((ptr2 == NULL) || (len2 < 1)) { return ptr1; diff --git a/utils.h b/utils.h index f2ccdac..929f249 100644 --- a/utils.h +++ b/utils.h @@ -24,7 +24,7 @@ /* Merges two memory fragments by reallocating the first one. Returns a pointer to the first memory segment or, if reallocated, to the new address. */ -void *memmerge(char *ptr1, char *ptr2, size_t len1, size_t len2); +void *memmerge(void *ptr1, void *ptr2, size_t len1, size_t len2); #endif diff --git a/xz.c b/xz.c index 243167d..5c80ee2 100644 --- a/xz.c +++ b/xz.c @@ -38,15 +38,12 @@ #endif /* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO(arginfo_void, 0) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO(arginfo_xzread, 0) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, length) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_xzwrite, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_xzwrite, 0, 0, 2) ZEND_ARG_INFO(0, fp) ZEND_ARG_INFO(0, str) ZEND_ARG_INFO(0, length) @@ -67,13 +64,19 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_xzdecode, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_xzopen, 0, 0, 2) + ZEND_ARG_INFO(0, filename) + ZEND_ARG_INFO(0, mode) + ZEND_ARG_INFO(0, compression_level) +ZEND_END_ARG_INFO() /* }}} */ /* {{{ xz_functions[] */ static const zend_function_entry xz_functions[] = { - PHP_FE(xzdecode, arginfo_void) - PHP_FE(xzopen, arginfo_void) - PHP_FE(xzencode, arginfo_void) + PHP_FE(xzdecode, arginfo_xzdecode) + PHP_FE(xzopen, arginfo_xzopen) + PHP_FE(xzencode, arginfo_xzencode) PHP_FALIAS(xzread, fread, arginfo_xzread) PHP_FALIAS(xzwrite, fwrite, arginfo_xzwrite) PHP_FALIAS(xzclose, fclose, arginfo_xzclose) @@ -247,7 +250,7 @@ PHP_FUNCTION(xzencode) lzma_end(&strm); - RETURN_STRINGL(out, out_len); + RETURN_STRINGL((char *)out, out_len); } /* }}} */ @@ -299,14 +302,14 @@ PHP_FUNCTION(xzdecode) strm.next_out = buff; } } - + (void)status; // avoid -Wunused-but-set-variable warning /* Merging last fragment. */ out = memmerge(out, buff, out_len, XZ_BUFFER_SIZE - strm.avail_out); out_len += XZ_BUFFER_SIZE - strm.avail_out; lzma_end(&strm); - RETURN_STRINGL(out, out_len); + RETURN_STRINGL((char *)out, out_len); } /* }}} */ diff --git a/xz_fopen_wrapper.c b/xz_fopen_wrapper.c index 8bd2843..4dc75a9 100644 --- a/xz_fopen_wrapper.c +++ b/xz_fopen_wrapper.c @@ -53,7 +53,7 @@ struct php_xz_stream_data_t { int fd; /* The type of access required. */ - char mode[4]; + char mode[64]; /* Compression level used. */ unsigned long level; @@ -69,7 +69,7 @@ static int php_xz_decompress(struct php_xz_stream_data_t *self) if (strm->avail_in == 0 && !php_stream_eof(self->stream)) { strm->next_in = self->in_buf; - strm->avail_in = php_stream_read(self->stream, self->in_buf, self->in_buf_sz); + strm->avail_in = php_stream_read(self->stream, (char *)self->in_buf, self->in_buf_sz); } lzma_ret ret = lzma_code(strm, action); @@ -92,14 +92,15 @@ static int php_xz_compress(struct php_xz_stream_data_t *self) { lzma_stream *strm = &self->strm; lzma_action action = LZMA_RUN; - int wrote = 0, to_write = strm->avail_in; + int to_write = strm->avail_in; while (strm->avail_in > 0) { lzma_ret ret = lzma_code(strm, action); size_t len = self->out_buf_sz - strm->avail_out; - php_stream_write(self->stream, self->out_buf, len); + php_stream_write(self->stream, (char *)self->out_buf, len); strm->next_out = self->out_buf; strm->avail_out = self->out_buf_sz; + (void)ret; // avoid -Wunused-but-set-variable warning } strm->next_in = self->in_buf; @@ -266,7 +267,7 @@ static int php_xziop_close(php_stream *stream, int close_handle) if (strm->avail_out < self->out_buf_sz) { size_t write_size = self->out_buf_sz - strm->avail_out; - php_stream_write(self->stream, self->out_buf, write_size); + php_stream_write(self->stream, (char *)self->out_buf, write_size); strm->next_out = self->out_buf; strm->avail_out = self->out_buf_sz; }