mirror of
https://github.com/curl/curl.git
synced 2024-12-15 06:40:09 +08:00
4399b0303a
The variable-sized encoding-specific storage of a struct contenc_writer currently relies on void * alignment that may be insufficient with regards to the specific storage fields, although having not caused any problems yet. In addition, gcc 11.3 issues a warning on access to fields of partially allocated structures that can occur when the specific storage size is 0: content_encoding.c: In function ‘Curl_build_unencoding_stack’: content_encoding.c:980:21: warning: array subscript ‘struct contenc_writer[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Warray-bounds] 980 | writer->handler = handler; | ~~~~~~~~~~~~~~~~^~~~~~~~~ In file included from content_encoding.c:49: memdebug.h:115:29: note: referencing an object of size 16 allocated by ‘curl_dbg_calloc’ 115 | #define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ content_encoding.c:977:60: note: in expansion of macro ‘calloc’ 977 | struct contenc_writer *writer = (struct contenc_writer *)calloc(1, sz); To solve both these problems, the current commit replaces the contenc_writer/params structure pairs by "subclasses" of struct contenc_writer. These are structures that contain a contenc_writer at offset 0. Proper field alignment is therefore handled by the compiler and full structure allocation is performed, silencing the warnings. Closes #9455
57 lines
2.3 KiB
C
57 lines
2.3 KiB
C
#ifndef HEADER_CURL_CONTENT_ENCODING_H
|
|
#define HEADER_CURL_CONTENT_ENCODING_H
|
|
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#include "curl_setup.h"
|
|
|
|
struct contenc_writer {
|
|
const struct content_encoding *handler; /* Encoding handler. */
|
|
struct contenc_writer *downstream; /* Downstream writer. */
|
|
};
|
|
|
|
/* Content encoding writer. */
|
|
struct content_encoding {
|
|
const char *name; /* Encoding name. */
|
|
const char *alias; /* Encoding name alias. */
|
|
CURLcode (*init_writer)(struct Curl_easy *data,
|
|
struct contenc_writer *writer);
|
|
CURLcode (*unencode_write)(struct Curl_easy *data,
|
|
struct contenc_writer *writer,
|
|
const char *buf, size_t nbytes);
|
|
void (*close_writer)(struct Curl_easy *data,
|
|
struct contenc_writer *writer);
|
|
size_t writersize;
|
|
};
|
|
|
|
|
|
CURLcode Curl_build_unencoding_stack(struct Curl_easy *data,
|
|
const char *enclist, int maybechunked);
|
|
CURLcode Curl_unencode_write(struct Curl_easy *data,
|
|
struct contenc_writer *writer,
|
|
const char *buf, size_t nbytes);
|
|
void Curl_unencode_cleanup(struct Curl_easy *data);
|
|
char *Curl_all_content_encodings(void);
|
|
|
|
#endif /* HEADER_CURL_CONTENT_ENCODING_H */
|