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

Fix GCC 10 warning with flag '-Wint-in-bool-context' #6537

Closed
wants to merge 2 commits into from
Closed

Fix GCC 10 warning with flag '-Wint-in-bool-context' #6537

wants to merge 2 commits into from

Conversation

MAntoniak
Copy link
Contributor

Avoid warning compiler: enum constant in boolean context

lib/transfer.c Outdated
@@ -435,7 +435,7 @@ CURLcode Curl_readrewind(struct Curl_easy *data)
; /* do nothing */
else if(data->state.httpreq == HTTPREQ_POST_MIME ||
data->state.httpreq == HTTPREQ_POST_FORM) {
if(Curl_mime_rewind(mimepart)) {
if(Curl_mime_rewind(mimepart) != CURLE_OK) {
Copy link
Member

Choose a reason for hiding this comment

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

I find this curious. What makes this particular condition a boolean context ? Surely we have the exact same construct in hundreds of places in the code. Also: why is this a warning/error in the first place?

Copy link
Member

Choose a reason for hiding this comment

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

A slightly better fix would probably be:

diff --git a/lib/transfer.c b/lib/transfer.c
index f9cdcd1d8..2f29b29d8 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -433,13 +433,14 @@ CURLcode Curl_readrewind(struct Curl_easy *data)
   }
   if(data->set.postfields)
     ; /* do nothing */
   else if(data->state.httpreq == HTTPREQ_POST_MIME ||
           data->state.httpreq == HTTPREQ_POST_FORM) {
-    if(Curl_mime_rewind(mimepart)) {
+    CURLcode result = Curl_mime_rewind(mimepart);
+    if(result) {
       failf(data, "Cannot rewind mime/post data");
-      return CURLE_SEND_FAIL_REWIND;
+      return result;
     }
   }
   else {
     if(data->set.seek_func) {
       int err;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also makes me wonder. So far we have used the ARM GCC 9.2.1 compiler and there were no warnings.
Without changing the compilation flags, we changed the compiler to ARM GCC 10.2.1 and a warning popped up.
I don't know what has changed between these versions ...

We use curl with HTTP protocol support only (by the way with CURL_DISABLE_MIME flag).
Hence, this is only one place of the warning.

I applied your patch and it works - no warnings! Which does not change the fact that it is a very interesting case.

@jay jay added the build label Jan 28, 2021
@bagder
Copy link
Member

bagder commented Jan 29, 2021

thanks!

@bagder bagder closed this in 1c1158a Jan 29, 2021
@MAntoniak MAntoniak deleted the Branch_95718021 branch January 31, 2021 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants