Skip to content

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

Closed
MAntoniak wants to merge 2 commits into
curl:masterfrom
MAntoniak:Branch_95718021
Closed

Fix GCC 10 warning with flag '-Wint-in-bool-context'#6537
MAntoniak wants to merge 2 commits into
curl:masterfrom
MAntoniak:Branch_95718021

Conversation

@MAntoniak

Copy link
Copy Markdown
Contributor

Avoid warning compiler: enum constant in boolean context

Comment thread lib/transfer.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

bagder commented Jan 29, 2021

Copy link
Copy Markdown
Member

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.

3 participants