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 build warning #11874

Closed
wants to merge 1 commit into from
Closed

Fix build warning #11874

wants to merge 1 commit into from

Conversation

vvb2060
Copy link
Contributor

@vvb2060 vvb2060 commented Sep 17, 2023

C/C++: [armeabi-v7a] Compile thumb  : curl_static <= connect.c
C/C++: curl-android/curl/src/main/native/curl/lib/connect.c:650:11: error: format specifies type 'long' but the argument has type 'timediff_t' (aka 'long long') [-Werror,-Wformat]
C/C++:           Curl_timediff(now, data->progress.t_startsingle));
C/C++:           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C/C++: 1 error generated.
C/C++: [armeabi-v7a] Compile thumb  : curl_static <= http2.c
C/C++: curl-android/curl/src/main/native/curl/lib/http2.c:2316:17: error: format specifies type 'long long' but the argument has type 'ssize_t' (aka 'int') [-Werror,-Wformat]
C/C++:                 (ssize_t)stream->upload_left,
C/C++:                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C/C++: curl-android/curl/src/main/native/curl/lib/curl_trc.h:123:38: note: expanded from macro 'CURL_TRC_CF'
C/C++:          Curl_trc_cf_infof(data, cf, __VA_ARGS__); } while(0)
C/C++:                                      ^~~~~~~~~~~
C/C++: 1 error generated.
C/C++: [armeabi-v7a] Compile thumb  : curl_static <= mqtt.c
C/C++: curl-android/curl/src/main/native/curl/lib/mqtt.c:303:55: error: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
C/C++:     failf(data, "Client ID length mismatched: [%lu]", strlen(client_id));
C/C++:                                                ~~~    ^~~~~~~~~~~~~~~~~
C/C++:                                                %zu
C/C++: curl-android/curl/src/main/native/curl/lib/mqtt.c:320:51: error: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
C/C++:       failf(data, "Username is too large: [%lu]", ulen);
C/C++:                                            ~~~    ^~~~
C/C++:                                            %zu
C/C++: curl-android/curl/src/main/native/curl/lib/mqtt.c:330:51: error: format specifies type 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') [-Werror,-Wformat]
C/C++:       failf(data, "Password is too large: [%lu]", plen);
C/C++:                                            ~~~    ^~~~
C/C++:                                            %zu
C/C++: 3 errors generated.
C/C++: [armeabi-v7a] Compile thumb  : curl_static <= url.c
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:892:11: error: format specifies type 'long' but the argument has type 'timediff_t' (aka 'long long') [-Werror,-Wformat]
C/C++:           idletime);
C/C++:           ^~~~~~~~
C/C++: curl-android/curl/src/main/native/curl/lib/curl_trc.h:120:27: note: expanded from macro 'infof'
C/C++:          Curl_infof(data, __VA_ARGS__); } while(0)
C/C++:                           ^~~~~~~~~~~
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:902:11: error: format specifies type 'long' but the argument has type 'timediff_t' (aka 'long long') [-Werror,-Wformat]
C/C++:           lifetime);
C/C++:           ^~~~~~~~
C/C++: curl-android/curl/src/main/native/curl/lib/curl_trc.h:120:27: note: expanded from macro 'infof'
C/C++:          Curl_infof(data, __VA_ARGS__); } while(0)
C/C++:                           ^~~~~~~~~~~
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:3044:52: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
C/C++:      ((conn->handler->protocol == CURLPROTO_HTTPS) ||
C/C++:                                                    ^
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:3044:52: note: use '|' for a bitwise operation
C/C++:      ((conn->handler->protocol == CURLPROTO_HTTPS) ||
C/C++:                                                    ^~
C/C++:                                                    |
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:3219:11: error: format specifies type 'long' but the argument has type 'timediff_t' (aka 'long long') [-Werror,-Wformat]
C/C++:           Curl_timediff(Curl_now(), data->progress.t_startsingle));
C/C++:           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C/C++: 1 warning and 3 errors generated.

@vvb2060
Copy link
Contributor Author

vvb2060 commented Sep 17, 2023

I ignored constant-logical-operand check because it had false positives(https://reviews.llvm.org/D142609), but I believe it did find some suspicious code.

C/C++: [arm64-v8a] Compile        : curl_static <= cf-h2-proxy.c
C/C++: curl-android/curl/src/main/native/curl/lib/cf-h2-proxy.c:236:39: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
C/C++:   if(data->state.dselect_bits != bits || 1) {
C/C++:                                       ^  ~
C/C++: curl-android/curl/src/main/native/curl/lib/cf-h2-proxy.c:236:39: note: use '|' for a bitwise operation
C/C++:   if(data->state.dselect_bits != bits || 1) {
C/C++:                                       ^~
C/C++:                                       |
C/C++: 1 warning generated.

Forgot to delete?

C/C++: curl-android/curl/src/main/native/curl/lib/hostip.c:789:41: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
C/C++:       else if(allowDOH && data->set.doh && !ipnum)
C/C++:                                         ^  ~~~~~~
C/C++: curl-android/curl/src/main/native/curl/lib/hostip.c:789:41: note: use '&' for a bitwise operation
C/C++:       else if(allowDOH && data->set.doh && !ipnum)
C/C++:                                         ^~
C/C++:                                         &
C/C++: curl-android/curl/src/main/native/curl/lib/hostip.c:789:41: note: remove constant to silence this warning
C/C++:       else if(allowDOH && data->set.doh && !ipnum)
C/C++:                                        ~^~~~~~~~~
C/C++: 1 warning generated.

llvm/llvm-project#63963

C/C++: [arm64-v8a] Compile        : curl_static <= http.c
C/C++: curl-android/curl/src/main/native/curl/lib/http.c:3788:49: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
C/C++:           ((conn->handler->flags & PROTOPT_SSL) ||
C/C++:                                                 ^
C/C++: curl-android/curl/src/main/native/curl/lib/http.c:3788:49: note: use '|' for a bitwise operation
C/C++:           ((conn->handler->flags & PROTOPT_SSL) ||
C/C++:                                                 ^~
C/C++:                                                 |
C/C++: curl-android/curl/src/main/native/curl/lib/http.c:3811:49: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
C/C++:           ((conn->handler->flags & PROTOPT_SSL) ||
C/C++:                                                 ^
C/C++: curl-android/curl/src/main/native/curl/lib/http.c:3811:49: note: use '|' for a bitwise operation
C/C++:           ((conn->handler->flags & PROTOPT_SSL) ||
C/C++:                                                 ^~
C/C++:                                                 |
C/C++: 2 warnings generated.

llvm/llvm-project#63963 It can be fixed by moving || into macro. Should this be fixed by curl, or is this a normal use case?

C/C++: [arm64-v8a] Compile        : curl_static <= url.c
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:3044:52: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
C/C++:      ((conn->handler->protocol == CURLPROTO_HTTPS) ||
C/C++:                                                    ^
C/C++: curl-android/curl/src/main/native/curl/lib/url.c:3044:52: note: use '|' for a bitwise operation
C/C++:      ((conn->handler->protocol == CURLPROTO_HTTPS) ||
C/C++:                                                    ^~
C/C++:                                                    |
C/C++: 1 warning generated.

Same as the previous one.

C/C++: curl-android/curl/src/main/native/curl/lib/setopt.c:495:40: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
C/C++:       if((data->set.postfieldsize < 0) ||
C/C++:                                        ^
C/C++: curl-android/curl/src/main/native/curl/lib/setopt.c:495:40: note: use '|' for a bitwise operation
C/C++:       if((data->set.postfieldsize < 0) ||
C/C++:                                        ^~
C/C++:                                        |
C/C++: 1 warning generated.

llvm/llvm-project#64356

@bagder
Copy link
Member

bagder commented Sep 17, 2023

@icing, the cf-h2-proxy.c:236:39 || 1 thing looks like a mistake we should fix, right?

@bagder
Copy link
Member

bagder commented Sep 17, 2023

The hostip.c:789:41 warning looks wrong. They are not constant values in the expression.

@bagder
Copy link
Member

bagder commented Sep 17, 2023

The http.c:3788:49 warning is wrong too.

@vvb2060
Copy link
Contributor Author

vvb2060 commented Sep 17, 2023

Yes, I think all but the first one are false positives. I show them all here to provide some practical use cases for llvm.

@bagder bagder closed this in 746dbc1 Sep 18, 2023
@bagder
Copy link
Member

bagder commented Sep 18, 2023

Thanks!

ptitSeb pushed a commit to wasix-org/curl that referenced this pull request Sep 25, 2023
@vvb2060 vvb2060 deleted the build branch February 7, 2024 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants