[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 07/07: http_chunked_compression: fixed errors
From: |
gnunet |
Subject: |
[libmicrohttpd] 07/07: http_chunked_compression: fixed errors |
Date: |
Wed, 01 Jun 2022 21:13:35 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit badf75607be186e10052cf04cb0319ced335d3a5
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Jun 1 22:06:05 2022 +0300
http_chunked_compression: fixed errors
---
src/examples/http_chunked_compression.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/src/examples/http_chunked_compression.c
b/src/examples/http_chunked_compression.c
index 7b8ed1fc..aa7bd2e5 100644
--- a/src/examples/http_chunked_compression.c
+++ b/src/examples/http_chunked_compression.c
@@ -1,6 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2019 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2019-2022 Evgeny Grin (Karlson2k)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -20,15 +21,21 @@
* @file http_chunked_compression.c
* @brief example for how to compress a chunked HTTP response
* @author Silvio Clecio (silvioprog)
+ * @author Karlson2k (Evgeny Grin)
*/
#include "platform.h"
+#ifndef ZLIB_CONST
+/* Correct API with const pointer for input data is required */
+#define ZLIB_CONST 1
+#endif /* ! ZLIB_CONST */
#include <zlib.h>
#include <microhttpd.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif /* HAVE_LIMITS_H */
#include <stddef.h>
+#include <stdint.h>
#ifndef SSIZE_MAX
#ifdef __SSIZE_MAX__
@@ -76,7 +83,7 @@ compress_buf (z_stream *strm, const void *src, size_t
src_size, size_t *offset,
flush = Z_SYNC_FLUSH;
}
*offset += strm->avail_in;
- strm->next_in = (Bytef *) src;
+ strm->next_in = (const Bytef *) src;
do
{
strm->avail_out = CHUNK;
@@ -92,7 +99,7 @@ compress_buf (z_stream *strm, const void *src, size_t
src_size, size_t *offset,
return MHD_NO;
}
*dest = tmp_dest;
- memcpy ((*dest) + ((*dest_size) - have), tmp, have);
+ memcpy (((uint8_t *) (*dest)) + ((*dest_size) - have), tmp, have);
}
while (0 == strm->avail_out);
}
@@ -109,6 +116,7 @@ read_cb (void *cls, uint64_t pos, char *mem, size_t size)
void *buf;
ssize_t ret;
size_t offset;
+ size_t r_size;
if (pos > SSIZE_MAX)
return MHD_CONTENT_READER_END_WITH_ERROR;
@@ -116,24 +124,20 @@ read_cb (void *cls, uint64_t pos, char *mem, size_t size)
src = malloc (size);
if (NULL == src)
return MHD_CONTENT_READER_END_WITH_ERROR;
- ret = fread (src, 1, size, holder->file);
- if (ret < 0)
+ r_size = fread (src, 1, size, holder->file);
+ if (0 == r_size)
{
- ret = MHD_CONTENT_READER_END_WITH_ERROR;
- goto done;
- }
- if (0 == ret)
- {
- ret = MHD_CONTENT_READER_END_OF_STREAM;
+ ret = (0 != ferror (holder->file)) ?
+ MHD_CONTENT_READER_END_WITH_ERROR : MHD_CONTENT_READER_END_OF_STREAM;
goto done;
}
- if (MHD_YES != compress_buf (&holder->stream, src, ret, &offset, &buf, &size,
- holder->buf))
+ if (MHD_YES != compress_buf (&holder->stream, src, r_size, &offset, &buf,
+ &size, holder->buf))
ret = MHD_CONTENT_READER_END_WITH_ERROR;
else
{
memcpy (mem, buf, size);
- ret = size;
+ ret = (ssize_t) size;
}
free (buf); /* Buf may be set even on error return. */
done:
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (1b8c52f1 -> badf7560), gnunet, 2022/06/01
- [libmicrohttpd] 03/07: microhttpd.h: fixed doxy, gnunet, 2022/06/01
- [libmicrohttpd] 01/07: connection: muted compiler warning, gnunet, 2022/06/01
- [libmicrohttpd] 04/07: src/examples/*fileserver*.c: added error checking, gnunet, 2022/06/01
- [libmicrohttpd] 07/07: http_chunked_compression: fixed errors,
gnunet <=
- [libmicrohttpd] 06/07: src/examples/demo{,_https}: added some error checking, fixed compiler warnings, gnunet, 2022/06/01
- [libmicrohttpd] 05/07: src/examples/benchmark{,_https}: simplified time calculation, gnunet, 2022/06/01
- [libmicrohttpd] 02/07: src/examples: muted compiler warnings, gnunet, 2022/06/01