mirror of
https://github.com/curl/curl.git
synced 2026-05-14 18:26:20 +03:00
Enable more picky compiler warnings. I've found these options in the nghttp3 project when implementing the CMake quick picky warning functionality for it [1]. `-Wunused-macros` was too noisy to keep around, but fixed a few issues it revealed while testing. - autotools: reflect the more precisely-versioned clang warnings. Follow-up to033f8e2a08#12324 - autotools: sync between clang and gcc the way we set `no-multichar`. - autotools: avoid setting `-Wstrict-aliasing=3` twice. - autotools: disable `-Wmissing-noreturn` for MSYS gcc targets [2]. It triggers in libtool-generated stub code. - lib/timeval: delete a redundant `!MSDOS` guard from a `WIN32` branch. - lib/curl_setup.h: delete duplicate declaration for `fileno`. Added in initial commitae1912cb0d(1999-12-29). This suggests this may not be needed anymore, but if it does, we may restore this for those specific (non-Windows) systems. - lib: delete unused macro `FTP_BUFFER_ALLOCSIZE` sincec1d6fe2aaa. - lib: delete unused macro `isxdigit_ascii` sincef65f750742. - lib/mqtt: delete unused macro `MQTT_HEADER_LEN`. - lib/multi: delete unused macro `SH_READ`/`SH_WRITE`. - lib/hostip: add `noreturn` function attribute via new `CURL_NORETURN` macro. - lib/mprintf: delete duplicate declaration for `Curl_dyn_vprintf`. - lib/rand: fix `-Wunreachable-code` and related fallouts [3]. - lib/setopt: fix `-Wunreachable-code-break`. - lib/system_win32 and lib/timeval: fix double declarations for `Curl_freq` and `Curl_isVistaOrGreater` in CMake UNITY mode [4]. - lib/warnless: fix double declarations in CMake UNITY mode [5]. This was due to force-disabling the header guard of `warnless.h` to to reapply it to source code coming after `warnless.c` in UNITY builds. This reapplied declarations too, causing the warnings. Solved by adding a header guard for the lines that actually need to be reapplied. - lib/vauth/digest: fix `-Wunreachable-code-break` [6]. - lib/vssh/libssh2: fix `-Wunreachable-code-break` and delete redundant block. - lib/vtls/sectransp: fix `-Wunreachable-code-break` [7]. - lib/vtls/sectransp: suppress `-Wunreachable-code`. Detected in `else` branches of dynamic feature checks, with results known at compile-time, e.g. ```c if(SecCertificateCopySubjectSummary) /* -> true */ ``` Likely fixable as a separate micro-project, but given SecureTransport is deprecated anyway, let's just silence these locally. - src/tool_help: delete duplicate declaration for `helptext`. - src/tool_xattr: fix `-Wunreachable-code`. - tests: delete duplicate declaration for `unitfail` [8]. - tests: delete duplicate declaration for `strncasecompare`. - tests/libtest: delete duplicate declaration for `gethostname`. Originally added in687df5c8c3(2010-08-02). Got complicated later:c49e9683b8If there are still systems around with warnings, we may restore the prototype, but limited for those systems. - tests/lib2305: delete duplicate declaration for `libtest_debug_config`. - tests/h2-download: fix `-Wunreachable-code-break`. [1]a70edb08e9/cmake/PickyWarningsC.cmake[2] https://ci.appveyor.com/project/curlorg/curl/builds/48553586/job/3qkgjauiqla5fj45?fullLog=true#L1675 [3] https://github.com/curl/curl/actions/runs/6880886309/job/18716044703?pr=12331#step:7:72 https://github.com/curl/curl/actions/runs/6883016087/job/18722707368?pr=12331#step:7:109 [4] https://ci.appveyor.com/project/curlorg/curl/builds/48555101/job/9g15qkrriklpf1ut#L204 [5] https://ci.appveyor.com/project/curlorg/curl/builds/48555101/job/9g15qkrriklpf1ut#L218 [6] https://github.com/curl/curl/actions/runs/6880886309/job/18716042927?pr=12331#step:7:290 [7] https://github.com/curl/curl/actions/runs/6891484996/job/18746659406?pr=12331#step:9:1193 [8] https://github.com/curl/curl/actions/runs/6882803986/job/18722082562?pr=12331#step:33:1870 Closes #12331
217 lines
6.7 KiB
C
217 lines
6.7 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.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 "tool_setup.h"
|
|
#define ENABLE_CURLX_PRINTF
|
|
/* use our own printf() functions */
|
|
#include "curlx.h"
|
|
|
|
#include "tool_help.h"
|
|
#include "tool_libinfo.h"
|
|
#include "tool_util.h"
|
|
#include "tool_version.h"
|
|
|
|
#include "memdebug.h" /* keep this as LAST include */
|
|
|
|
#ifdef MSDOS
|
|
# define USE_WATT32
|
|
#endif
|
|
|
|
struct category_descriptors {
|
|
const char *opt;
|
|
const char *desc;
|
|
curlhelp_t category;
|
|
};
|
|
|
|
static const struct category_descriptors categories[] = {
|
|
{"auth", "Different types of authentication methods", CURLHELP_AUTH},
|
|
{"connection", "Low level networking operations",
|
|
CURLHELP_CONNECTION},
|
|
{"curl", "The command line tool itself", CURLHELP_CURL},
|
|
{"dns", "General DNS options", CURLHELP_DNS},
|
|
{"file", "FILE protocol options", CURLHELP_FILE},
|
|
{"ftp", "FTP protocol options", CURLHELP_FTP},
|
|
{"http", "HTTP and HTTPS protocol options", CURLHELP_HTTP},
|
|
{"imap", "IMAP protocol options", CURLHELP_IMAP},
|
|
/* important is left out because it is the default help page */
|
|
{"misc", "Options that don't fit into any other category", CURLHELP_MISC},
|
|
{"output", "Filesystem output", CURLHELP_OUTPUT},
|
|
{"pop3", "POP3 protocol options", CURLHELP_POP3},
|
|
{"post", "HTTP Post specific options", CURLHELP_POST},
|
|
{"proxy", "All options related to proxies", CURLHELP_PROXY},
|
|
{"scp", "SCP protocol options", CURLHELP_SCP},
|
|
{"sftp", "SFTP protocol options", CURLHELP_SFTP},
|
|
{"smtp", "SMTP protocol options", CURLHELP_SMTP},
|
|
{"ssh", "SSH protocol options", CURLHELP_SSH},
|
|
{"telnet", "TELNET protocol options", CURLHELP_TELNET},
|
|
{"tftp", "TFTP protocol options", CURLHELP_TFTP},
|
|
{"tls", "All TLS/SSL related options", CURLHELP_TLS},
|
|
{"upload", "All options for uploads",
|
|
CURLHELP_UPLOAD},
|
|
{"verbose", "Options related to any kind of command line output of curl",
|
|
CURLHELP_VERBOSE},
|
|
{NULL, NULL, CURLHELP_HIDDEN}
|
|
};
|
|
|
|
|
|
static void print_category(curlhelp_t category)
|
|
{
|
|
unsigned int i;
|
|
size_t longopt = 5;
|
|
size_t longdesc = 5;
|
|
|
|
for(i = 0; helptext[i].opt; ++i) {
|
|
size_t len;
|
|
if(!(helptext[i].categories & category))
|
|
continue;
|
|
len = strlen(helptext[i].opt);
|
|
if(len > longopt)
|
|
longopt = len;
|
|
len = strlen(helptext[i].desc);
|
|
if(len > longdesc)
|
|
longdesc = len;
|
|
}
|
|
if(longopt + longdesc > 80)
|
|
longopt = 80 - longdesc;
|
|
|
|
for(i = 0; helptext[i].opt; ++i)
|
|
if(helptext[i].categories & category) {
|
|
printf(" %-*s %s\n", (int)longopt, helptext[i].opt, helptext[i].desc);
|
|
}
|
|
}
|
|
|
|
/* Prints category if found. If not, it returns 1 */
|
|
static int get_category_content(const char *category)
|
|
{
|
|
unsigned int i;
|
|
for(i = 0; categories[i].opt; ++i)
|
|
if(curl_strequal(categories[i].opt, category)) {
|
|
printf("%s: %s\n", categories[i].opt, categories[i].desc);
|
|
print_category(categories[i].category);
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
/* Prints all categories and their description */
|
|
static void get_categories(void)
|
|
{
|
|
unsigned int i;
|
|
for(i = 0; categories[i].opt; ++i)
|
|
printf(" %-11s %s\n", categories[i].opt, categories[i].desc);
|
|
}
|
|
|
|
|
|
void tool_help(char *category)
|
|
{
|
|
puts("Usage: curl [options...] <url>");
|
|
/* If no category was provided */
|
|
if(!category) {
|
|
const char *category_note = "\nThis is not the full help, this "
|
|
"menu is stripped into categories.\nUse \"--help category\" to get "
|
|
"an overview of all categories.\nFor all options use the manual"
|
|
" or \"--help all\".";
|
|
print_category(CURLHELP_IMPORTANT);
|
|
puts(category_note);
|
|
}
|
|
/* Lets print everything if "all" was provided */
|
|
else if(curl_strequal(category, "all"))
|
|
/* Print everything except hidden */
|
|
print_category(~(CURLHELP_HIDDEN));
|
|
/* Lets handle the string "category" differently to not print an errormsg */
|
|
else if(curl_strequal(category, "category"))
|
|
get_categories();
|
|
/* Otherwise print category and handle the case if the cat was not found */
|
|
else if(get_category_content(category)) {
|
|
puts("Invalid category provided, here is a list of all categories:\n");
|
|
get_categories();
|
|
}
|
|
free(category);
|
|
}
|
|
|
|
static bool is_debug(void)
|
|
{
|
|
const char *const *builtin;
|
|
for(builtin = feature_names; *builtin; ++builtin)
|
|
if(curl_strequal("debug", *builtin))
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
void tool_version_info(void)
|
|
{
|
|
const char *const *builtin;
|
|
if(is_debug())
|
|
fprintf(tool_stderr, "WARNING: this libcurl is Debug-enabled, "
|
|
"do not use in production\n\n");
|
|
|
|
printf(CURL_ID "%s\n", curl_version());
|
|
#ifdef CURL_PATCHSTAMP
|
|
printf("Release-Date: %s, security patched: %s\n",
|
|
LIBCURL_TIMESTAMP, CURL_PATCHSTAMP);
|
|
#else
|
|
printf("Release-Date: %s\n", LIBCURL_TIMESTAMP);
|
|
#endif
|
|
if(built_in_protos[0]) {
|
|
printf("Protocols:");
|
|
for(builtin = built_in_protos; *builtin; ++builtin) {
|
|
/* Special case: do not list rtmp?* protocols.
|
|
They may only appear together with "rtmp" */
|
|
if(!curl_strnequal(*builtin, "rtmp", 4) || !builtin[0][4])
|
|
printf(" %s", *builtin);
|
|
}
|
|
puts(""); /* newline */
|
|
}
|
|
if(feature_names[0]) {
|
|
printf("Features:");
|
|
for(builtin = feature_names; *builtin; ++builtin)
|
|
printf(" %s", *builtin);
|
|
puts(""); /* newline */
|
|
}
|
|
if(strcmp(CURL_VERSION, curlinfo->version)) {
|
|
printf("WARNING: curl and libcurl versions do not match. "
|
|
"Functionality may be affected.\n");
|
|
}
|
|
}
|
|
|
|
void tool_list_engines(void)
|
|
{
|
|
CURL *curl = curl_easy_init();
|
|
struct curl_slist *engines = NULL;
|
|
|
|
/* Get the list of engines */
|
|
curl_easy_getinfo(curl, CURLINFO_SSL_ENGINES, &engines);
|
|
|
|
puts("Build-time engines:");
|
|
if(engines) {
|
|
for(; engines; engines = engines->next)
|
|
printf(" %s\n", engines->data);
|
|
}
|
|
else {
|
|
puts(" <none>");
|
|
}
|
|
|
|
/* Cleanup the list of engines */
|
|
curl_slist_free_all(engines);
|
|
curl_easy_cleanup(curl);
|
|
}
|