mirror of
https://github.com/curl/curl.git
synced 2026-04-15 01:05:56 +08:00
The issues found fell into these categories, with the applied fixes:
- const was accidentally stripped.
Adjust code to not cast or cast with const.
- const/volatile missing from arguments, local variables.
Constify arguments or variables, adjust/delete casts. Small code
changes in a few places.
- const must be stripped because an API dependency requires it.
Strip `const` with `CURL_UNCONST()` macro to silence the warning out
of our control. These happen at API boundaries. Sometimes they depend
on dependency version, which this patch handles as necessary. Also
enable const support for the zlib API, using `ZLIB_CONST`. Supported
by zlib 1.2.5.2 and newer.
- const must be stripped because a curl API requires it.
Strip `const` with `CURL_UNCONST()` macro to silence the warning out
of our immediate control. For example we promise to send a non-const
argument to a callback, though the data is const internally.
- other cases where we may avoid const stripping by code changes.
Also silenced with `CURL_UNCONST()`.
- there are 3 places where `CURL_UNCONST()` is cast again to const.
To silence this type of warning:
```
lib/vquic/curl_osslq.c:1015:29: error: to be safe all intermediate
pointers in cast from 'unsigned char **' to 'const unsigned char **'
must be 'const' qualified [-Werror=cast-qual]
lib/cf-socket.c:734:32: error: to be safe all intermediate pointers in
cast from 'char **' to 'const char **' must be 'const' qualified
[-Werror=cast-qual]
```
There may be a better solution, but I couldn't find it.
These cases are handled in separate subcommits, but without further
markup.
If you see a `-Wcast-qual` warning in curl, we appreciate your report
about it.
Closes #16142
79 lines
2.3 KiB
C
79 lines
2.3 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) 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.haxx.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 "test.h"
|
|
|
|
typedef struct
|
|
{
|
|
char *buf;
|
|
size_t len;
|
|
} put_buffer;
|
|
|
|
static size_t put_callback(char *ptr, size_t size, size_t nmemb, void *stream)
|
|
{
|
|
put_buffer *putdata = (put_buffer *)stream;
|
|
size_t totalsize = size * nmemb;
|
|
size_t tocopy = (putdata->len < totalsize) ? putdata->len : totalsize;
|
|
memcpy(ptr, putdata->buf, tocopy);
|
|
putdata->len -= tocopy;
|
|
putdata->buf += tocopy;
|
|
return tocopy;
|
|
}
|
|
|
|
CURLcode test(char *URL)
|
|
{
|
|
CURL *curl;
|
|
CURLcode res = CURLE_OK;
|
|
const char *testput = "This is test PUT data\n";
|
|
put_buffer pbuf;
|
|
|
|
curl_global_init(CURL_GLOBAL_DEFAULT);
|
|
|
|
easy_init(curl);
|
|
|
|
/* PUT */
|
|
easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
|
easy_setopt(curl, CURLOPT_HEADER, 1L);
|
|
easy_setopt(curl, CURLOPT_READFUNCTION, put_callback);
|
|
pbuf.buf = (char *)CURL_UNCONST(testput);
|
|
pbuf.len = strlen(testput);
|
|
easy_setopt(curl, CURLOPT_READDATA, &pbuf);
|
|
easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput));
|
|
easy_setopt(curl, CURLOPT_URL, URL);
|
|
res = curl_easy_perform(curl);
|
|
if(res)
|
|
goto test_cleanup;
|
|
|
|
/* POST */
|
|
easy_setopt(curl, CURLOPT_POST, 1L);
|
|
easy_setopt(curl, CURLOPT_POSTFIELDS, testput);
|
|
easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput));
|
|
res = curl_easy_perform(curl);
|
|
|
|
test_cleanup:
|
|
curl_easy_cleanup(curl);
|
|
curl_global_cleanup();
|
|
return res;
|
|
}
|