Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure compiles on Fedora with GCC 12 #3132

Closed
wants to merge 1 commit into from

Conversation

bkmgit
Copy link
Contributor

@bkmgit bkmgit commented Dec 27, 2022

Fixes the problem when compiling with Gcc 12.2.1 20221121 and curl 7.87.0 that one gets
In file included from /usr/include/curl/curl.h:3195,
                 from turnrest.c:21:
turnrest.c: In function ‘janus_turnrest_request’:
turnrest.c:168:9: error: void value not ignored as it ought to be
  168 |         curl_easy_setopt(curl, api_http_get ? CURLOPT_HTTPGET : CURLOPT_POST, 1);
      |         ^
@januscla
Copy link

Thanks for your contribution, @bkmgit! Please make sure you sign our CLA, as it's a required step before we can merge this.

@atoppi
Copy link
Member

atoppi commented Dec 27, 2022

Hi @bkmgit, I don't understand why the PR should solve the error returned by the compiiler

void value not ignored as it ought to be

means that we are considering something void / returning void like it is not like that.
I don't understand why transforming a ternary operator in a condition evaluation should fix the issue.

Could you please clarify the purpose of the fix?

@bkmgit
Copy link
Contributor Author

bkmgit commented Dec 27, 2022

Expect it maybe parsing or evaluation that is occurring incorrectly.
The line creating the problem seems to be https://github.com/curl/curl/blob/c12fb3ddaf48e709a7a4deaa55ec485e4df163ee/include/curl/curl.h#L3195
Seems to be that typechecking does not support multiple options:
https://github.com/curl/curl/blob/c12fb3ddaf48e709a7a4deaa55ec485e4df163ee/include/curl/typecheck-gcc.h

@bkmgit
Copy link
Contributor Author

bkmgit commented Dec 27, 2022

If it would be helpful, can also add a config to do CI on Fedora Linux.

@atoppi
Copy link
Member

atoppi commented Dec 28, 2022

If it would be helpful, can also add a config to do CI on Fedora Linux.

I'd prefer not to start adding different linux distros on the CI.
Also, AFAIR, @lminiero uses Fedora on his workstation, so that should be easy enough to replicate.

Anyway since the change is minor and harmless I don't see any reason not to merge this.

@lminiero
Copy link
Member

I'd also like to first understand why a ternary operator causes the compiler to barf, before just merging, especially since we use those operators all over the place. Maybe it just needs wrapping in parenthesis to make the curl macros happy?

@bkmgit
Copy link
Contributor Author

bkmgit commented Dec 28, 2022

Can examine using parentheses. The header file curl.h has not changed between curl 7.86.0 and curl 7.87.0 . Files with changes that have curl_setopt

$ git diff c12fb3d cd95ee9 tool_operate.c
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 79db063a5..43c1c5e6c 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -328,7 +328,6 @@ static CURLcode pre_transfer(struct GlobalConfig *global,
     }
     per->input.fd = per->infd;
   }
-  per->start = tvnow();
   return result;
 }
 
@@ -731,7 +730,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
   if(config->postfields) {
     if(config->use_httpget) {
       if(!httpgetfields) {
-        /* Use the postfields data for an HTTP get */
+        /* Use the postfields data for a http get */
         httpgetfields = state->httpgetfields = strdup(config->postfields);
         Curl_safefree(config->postfields);
         if(!httpgetfields) {
@@ -969,21 +968,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           /* open file for output: */
           if(strcmp(config->headerfile, "-")) {
             FILE *newfile;
-
-            /*
-             * this checks if the previous transfer had the same
-             * OperationConfig, which would mean, that the an output file has
-             * already been created and data can be appened to it, instead
-             * of overwriting it.
-             * TODO: Consider placing the file handle inside the
-             * OperationConfig, so that it does not need to be opened/closed
-             * for every transfer.
-             */
-            if(per->prev && per->prev->config == config)
-              newfile = fopen(config->headerfile, "ab+");
-            else
-              newfile = fopen(config->headerfile, "wb+");
-
+            newfile = fopen(config->headerfile, per->prev == NULL?"wb":"ab");
             if(!newfile) {
               warnf(global, "Failed to open %s\n", config->headerfile);
               result = CURLE_WRITE_ERROR;
@@ -1203,30 +1188,22 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           global->isatty = orig_isatty;
         }
 
-        if(httpgetfields || config->query) {
-          char *q = httpgetfields ? httpgetfields : config->query;
+        if(httpgetfields) {
           CURLU *uh = curl_url();
           if(uh) {
             char *updated;
             if(curl_url_set(uh, CURLUPART_URL, per->this_url,
-                            CURLU_GUESS_SCHEME)) {
-              result = CURLE_FAILED_INIT;
-              errorf(global, "(%d) Could not parse the URL, "
-                     "failed to set query\n", result);
-              config->synthetic_error = TRUE;
-            }
-            else if(curl_url_set(uh, CURLUPART_QUERY, q, CURLU_APPENDQUERY) ||
-                    curl_url_get(uh, CURLUPART_URL, &updated,
-                                 CURLU_GUESS_SCHEME)) {
+                            CURLU_GUESS_SCHEME) ||
+               curl_url_set(uh, CURLUPART_QUERY, httpgetfields,
+                            CURLU_APPENDQUERY) ||
+               curl_url_get(uh, CURLUPART_URL, &updated, CURLU_GUESS_SCHEME)) {
+              curl_url_cleanup(uh);
               result = CURLE_OUT_OF_MEMORY;
+              break;
             }
-            else {
-              Curl_safefree(per->this_url); /* free previous URL */
-              per->this_url = updated; /* use our new URL instead! */
-            }
+            Curl_safefree(per->this_url); /* free previous URL */
+            per->this_url = updated; /* use our new URL instead! */
             curl_url_cleanup(uh);
-            if(result)
-              break;
           }
         }
 
@@ -1251,15 +1228,6 @@ static CURLcode single_transfer(struct GlobalConfig *global,
 
         use_proto = url_proto(per->this_url);
 
-        /* On most modern OSes, exiting works thoroughly,
-           we'll clean everything up via exit(), so don't bother with
-           slow cleanups. Crappy ones might need to skip this.
-           Note: avoid having this setopt added to the --libcurl source
-           output. */
-        result = curl_easy_setopt(curl, CURLOPT_QUICK_EXIT, 1L);
-        if(result)
-          break;
-
         if(!config->tcp_nodelay)
           my_setopt(curl, CURLOPT_TCP_NODELAY, 0L);
 
@@ -1275,7 +1243,6 @@ static CURLcode single_transfer(struct GlobalConfig *global,
 
         /* for uploads */
         input->config = config;
-        input->per = per;
         /* Note that if CURLOPT_READFUNCTION is fread (the default), then
          * lib/telnet.c will Curl_poll() on the input file descriptor
          * rather than calling the READFUNCTION at regular intervals.
@@ -1377,7 +1344,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           per->errorbuffer = global_errorbuffer;
           my_setopt(curl, CURLOPT_ERRORBUFFER, global_errorbuffer);
         }
-        my_setopt(curl, CURLOPT_TIMEOUT_MS, config->timeout_ms);
+        my_setopt(curl, CURLOPT_TIMEOUT_MS, (long)(config->timeout * 1000));
 
         switch(config->httpreq) {
         case HTTPREQ_SIMPLEPOST:
@@ -1437,8 +1404,9 @@ static CURLcode single_transfer(struct GlobalConfig *global,
 
           if(config->httpversion)
             my_setopt_enum(curl, CURLOPT_HTTP_VERSION, config->httpversion);
-          else if(feature_http2)
+          else if(curlinfo->features & CURL_VERSION_HTTP2) {
             my_setopt_enum(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
+          }
 
           /* curl 7.19.1 (the 301 version existed in 7.18.2),
              303 was added in 7.26.0 */
@@ -1553,7 +1521,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         if(config->ssl_ec_curves)
           my_setopt_str(curl, CURLOPT_SSL_EC_CURVES, config->ssl_ec_curves);
 
-        if(feature_ssl) {
+        if(curlinfo->features & CURL_VERSION_SSL) {
           /* Check if config->cert is a PKCS#11 URI and set the
            * config->cert_type if necessary */
           if(config->cert) {
@@ -1864,7 +1832,8 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
 
         /* new in libcurl 7.7: */
-        my_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, config->connecttimeout_ms);
+        my_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
+                  (long)(config->connecttimeout * 1000));
 
         if(config->doh_url)
           my_setopt_str(curl, CURLOPT_DOH_URL, config->doh_url);
@@ -2052,7 +2021,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           my_setopt_slist(curl, CURLOPT_CONNECT_TO, config->connect_to);
 
         /* new in 7.21.4 */
-        if(feature_tls_srp) {
+        if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
           if(config->tls_username)
             my_setopt_str(curl, CURLOPT_TLSAUTH_USERNAME,
                           config->tls_username);
@@ -2110,9 +2079,9 @@ static CURLcode single_transfer(struct GlobalConfig *global,
           my_setopt_str(curl, CURLOPT_DEFAULT_PROTOCOL, config->proto_default);
 
         /* new in 7.47.0 */
-        if(config->expect100timeout_ms > 0)
+        if(config->expect100timeout > 0)
           my_setopt_str(curl, CURLOPT_EXPECT_100_TIMEOUT_MS,
-                        config->expect100timeout_ms);
+                        (long)(config->expect100timeout*1000));
 
         /* new in 7.48.0 */
         if(config->tftp_no_options && proto_tftp)
@@ -2329,8 +2298,7 @@ static CURLcode parallel_transfers(struct GlobalConfig *global,
           curl_easy_getinfo(easy, CURLINFO_PRIVATE, (void *)&ended);
           curl_multi_remove_handle(multi, easy);
 
-          if(ended->abort && (tres == CURLE_ABORTED_BY_CALLBACK) &&
-             ended->errorbuffer) {
+          if(ended->abort && tres == CURLE_ABORTED_BY_CALLBACK) {
             msnprintf(ended->errorbuffer, CURL_ERROR_SIZE,
                       "Transfer aborted due to critical error "
                       "in another transfer");
@@ -2418,6 +2386,7 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
     bool retry;
     long delay_ms;
     bool bailout = FALSE;
+    struct timeval start;
     result = pre_transfer(global, per);
     if(result)
       break;
@@ -2428,6 +2397,7 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
         break;
     }
 
+    start = tvnow();
 #ifdef CURLDEBUG
     if(global->test_event_based)
       result = curl_easy_perform_ev(per->curl);
@@ -2459,7 +2429,7 @@ static CURLcode serial_transfers(struct GlobalConfig *global,
     if(per && global->ms_per_transfer) {
       /* how long time did the most recent transfer take in number of
          milliseconds */
-      long milli = tvdiff(tvnow(), per->start);
+      long milli = tvdiff(tvnow(), start);
       if(milli < global->ms_per_transfer) {
         notef(global, "Transfer took %ld ms, waits %ldms as set by --rate\n",
               milli, global->ms_per_transfer - milli);
@@ -2652,10 +2622,9 @@ CURLcode operate(struct GlobalConfig *global, int argc, argv_item_t argv[])
   CURLcode result = CURLE_OK;
   char *first_arg = argc > 1 ? curlx_convert_tchar_to_UTF8(argv[1]) : NULL;
 
+  /* Setup proper locale from environment */
 #ifdef HAVE_SETLOCALE
-  /* Override locale for number parsing (only) */
   setlocale(LC_ALL, "");
-  setlocale(LC_NUMERIC, "C");
 #endif
 
   /* Parse .curlrc if necessary */

and

$ git diff c12fb3d cd95ee9 tool_setopt.c
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index dae7704cd..3db2fe3c6 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -710,4 +710,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
 
 #else /* CURL_DISABLE_LIBCURL_OPTION */
 
+#include "tool_cfgable.h"
+#include "tool_setopt.h"
+
 #endif /* CURL_DISABLE_LIBCURL_OPTION */

@lminiero
Copy link
Member

lminiero commented Jan 2, 2023

@bkmgit did you have a chance to test with parentheses?

curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
}else{
curl_easy_setopt(curl, CURLOPT_POST, 1L);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small editorial notes: per our code style, you need a space between parentheses, so

if(api_http_get) {

and the else needs spaces too:

} else {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review and suggestions. Probably no longer needed.

@bkmgit
Copy link
Contributor Author

bkmgit commented Jan 2, 2023

Closing in favor of #3138 which uses parentheses.

@bkmgit bkmgit closed this Jan 2, 2023
@bkmgit bkmgit deleted the compilation-fix-fedora branch January 4, 2023 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants