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

tidy-up: delete, comment or scope C macros reported unused #16279

Closed
wants to merge 43 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented Feb 9, 2025

To reduce the number -Wunused-macro compiler warnings:

  • delete unused macros.
  • comment out unused macro that are part of a set.
  • move macros into the scope they are used.

This may be useful to enable by default, but there are tricky cases that
I didn't manage to fix and paused the effort. E.g. internal features
checks in openssl.c. There is more, once those are fixed.


@@ -269,9 +268,6 @@ Curl_sha512_256_finish(unsigned char *digest,

#else /* No system or TLS backend SHA-512/256 implementation available */

/* Use local implementation */
#define HAS_SHA512_256_IMPLEMENTATION 1
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure about the intent here, the macro is set twice after the last use.
Hopefully the code is OK.

# define DEBUG_OUT(x) x
#else
# define DEBUG_OUT(x) Curl_nop_stmt
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

It'd be ideal to replace this with TRC logging, esp. in vauth/ntlm.c guard some log output behind its own DEBUG_ME macro.

#define CURL_MASK_SLONG (CURL_MASK_ULONG >> 1)

#define CURL_MASK_UCOFFT ((unsigned CURL_TYPEOF_CURL_OFF_T)~0)
#define CURL_MASK_SCOFFT (CURL_MASK_UCOFFT >> 1)
Copy link
Member Author

@vszakats vszakats Feb 9, 2025

Choose a reason for hiding this comment

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

Also a series/set. I surmised it's unlikely these get used given warnless hasn't been expanding for a good while.

@vszakats vszakats marked this pull request as draft February 9, 2025 21:35
@vszakats vszakats changed the title tidy-up: delete or scope unused C macros tidy-up: delete or scope C macros reported as unused Feb 9, 2025
@vszakats vszakats marked this pull request as ready for review February 10, 2025 03:35
@vszakats vszakats changed the title tidy-up: delete or scope C macros reported as unused tidy-up: delete or scope C macros reported unused Feb 10, 2025
@vszakats vszakats changed the title tidy-up: delete or scope C macros reported unused tidy-up: delete, comment or scope C macros reported unused Feb 12, 2025
… source

Fixes unused macro warning:
```
tests/http/clients/ws-data.c:44:0: warning: macro "WIN32_LEAN_AND_MEAN" is not used [-Wunused-macros]
```
```
docs/examples/externalsocket.c:30:0: warning: macro "_WINSOCK_DEPRECATED_NO_WARNINGS" is not used [-Wunused-macros]
lib/dynbuf.c:35: warning: macro "DYNINIT" is not used [-Wunused-macros]
lib/version.c:426:0: warning: macro "idn_present" is not used [-Wunused-macros]
src/tool_doswin.c:49:0: warning: macro "_use_lfn" is not used [-Wunused-macros]
```
```
lib/cf-socket.c:940:0: warning: macro "NW_RECV_CHUNK_SIZE" is not used [-Wunused-macros]
lib/cf-socket.c:941:0: warning: macro "NW_RECV_CHUNKS" is not used [-Wunused-macros]
lib/cf-socket.c:942:0: warning: macro "NW_SMALL_READS" is not used [-Wunused-macros]
```
```
lib/content_encoding.c:68:0: warning: macro "DECOMPRESS_BUFFER_SIZE" is not used [-Wunused-macros]
```
```
lib/curl_ntlm_core.c:147:0: warning: macro "NTLMv2_BLOB_SIGNATURE" is not used [-Wunused-macros]
lib/curl_ntlm_core.c:148:0: warning: macro "NTLMv2_BLOB_LEN" is not used [-Wunused-macros]
```
```
lib/curl_sha512_256.c:273:0: warning: macro "HAS_SHA512_256_IMPLEMENTATION" is not used [-Wunused-macros]
```
```
lib/doh.c:50:0: warning: macro "LOCAL_PB_HEXMAX" is not used [-Wunused-macros]
```
There is a copy of this in vauth/ntlm.c, which is used.
It'd be nice to migrate these to curl_trc().

```
lib/http_ntlm.c:61:0: warning: macro "DEBUG_OUT" is not used [-Wunused-macros]
```
```
lib/inet_ntop.c:41:0: warning: macro "INADDRSZ" is not used [-Wunused-macros]
```
```
lib/url.c:840:0: warning: macro "ssh_config_matches" is not used [-Wunused-macros]
```
```
lib/vauth/digest.c:53:0: warning: macro "SESSION_ALGO" is not used [-Wunused-macros]
lib/vauth/digest.c:55:0: warning: macro "ALGO_MD5" is not used [-Wunused-macros]
lib/vauth/digest.c:56:0: warning: macro "ALGO_MD5SESS" is not used [-Wunused-macros]
lib/vauth/digest.c:57:0: warning: macro "ALGO_SHA256" is not used [-Wunused-macros]
lib/vauth/digest.c:58:0: warning: macro "ALGO_SHA256SESS" is not used [-Wunused-macros]
lib/vauth/digest.c:59:0: warning: macro "ALGO_SHA512_256" is not used [-Wunused-macros]
lib/vauth/digest.c:60:0: warning: macro "ALGO_SHA512_256SESS" is not used [-Wunused-macros]
```
```
lib/vtls/schannel.c:236:0: warning: macro "LONGEST_ALG_ID" is not used [-Wunused-macros]
```
```
lib/vtls/schannel.c:84:0: warning: macro "BCRYPT_CHACHA20_POLY1305_ALGORITHM" is not used [-Wunused-macros]
```
```
lib/warnless.c:48:9: warning: macro "CURL_MASK_SCHAR" is not used [-Wunused-macros]
lib/warnless.c:51:9: warning: macro "CURL_MASK_SSHORT" is not used [-Wunused-macros]
lib/warnless.c:57:9: warning: macro "CURL_MASK_SLONG" is not used [-Wunused-macros]
lib/warnless.c:59:9: warning: macro "CURL_MASK_UCOFFT" is not used [-Wunused-macros]
lib/warnless.c:60:9: warning: macro "CURL_MASK_SCOFFT" is not used [-Wunused-macros]
```
```
src/tool_cb_see.c:38:0: warning: macro "OUR_MAX_SEEK_L" is not used [-Wunused-macros]
src/tool_cb_see.c:39:0: warning: macro "OUR_MAX_SEEK_O" is not used [-Wunused-macros]
```
```
lib/cookie.c:489:0: warning: macro "CERR_PSL" is not used [-Wunused-macros]
```
```
tests/server/rtspd.c:71:0: warning: macro "REQBUFSIZ_TXT" is not used [-Wunused-macros]
```
```
tests/server/mqttd.c:72:0: warning: macro "EAGAIN" is not used [-Wunused-macros]
tests/server/mqttd.c:74:0: warning: macro "ENOMEM" is not used [-Wunused-macros]
tests/server/mqttd.c:76:0: warning: macro "EINVAL" is not used [-Wunused-macros]
tests/server/socksd.c:90:0: warning: macro "EAGAIN" is not used [-Wunused-macros]
tests/server/socksd.c:92:0: warning: macro "ENOMEM" is not used [-Wunused-macros]
tests/server/socksd.c:94:0: warning: macro "EINVAL" is not used [-Wunused-macros]
```
```
tests/server/mqttd.c:97:0: warning: macro "MQTT_CONNACK_LEN" is not used [-Wunused-macros]
tests/server/mqttd.c:98:0: warning: macro "MQTT_SUBACK_LEN" is not used [-Wunused-macros]
tests/server/mqttd.c:99:0: warning: macro "MQTT_CLIENTID_LEN" is not used [-Wunused-macros]
```
```
lib/mqtt.c:50:0: warning: macro "MQTT_MSG_CONNACK" is not used [-Wunused-macros]
tests/server/mqttd.c:92:0: warning: macro "MQTT_MSG_PUBACK" is not used [-Wunused-macros]
```
```
lib/smb.c:80:0: warning: macro "SMB_FLAGS2_UNICODE_STRINGS" is not used [-Wunused-macros]
```
```
lib/vtls/x509asn1.c:79:0: warning: macro "CURL_ASN1_OBJECT_DESCRIPTOR" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:80:0: warning: macro "CURL_ASN1_INSTANCE_OF" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:81:0: warning: macro "CURL_ASN1_REAL" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:83:0: warning: macro "CURL_ASN1_EMBEDDED" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:85:0: warning: macro "CURL_ASN1_RELATIVE_OID" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:86:0: warning: macro "CURL_ASN1_SEQUENCE" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:87:0: warning: macro "CURL_ASN1_SET" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:91:0: warning: macro "CURL_ASN1_VIDEOTEX_STRING" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:95:0: warning: macro "CURL_ASN1_GRAPHIC_STRING" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:97:0: warning: macro "CURL_ASN1_GENERAL_STRING" is not used [-Wunused-macros]
lib/vtls/x509asn1.c:99:0: warning: macro "CURL_ASN1_CHARACTER_STRING" is not used [-Wunused-macros]
```
```
src/tool_setopt.c:188:0: warning: macro "DECL0" is not used [-Wunused-macros]
src/tool_setopt.c:191:0: warning: macro "DATA0" is not used [-Wunused-macros]
src/tool_setopt.c:193:0: warning: macro "DATA2" is not used [-Wunused-macros]
src/tool_setopt.c:201:0: warning: macro "CLEAN0" is not used [-Wunused-macros]
src/tool_setopt.c:204:0: warning: macro "REM0" is not used [-Wunused-macros]
src/tool_setopt.c:205:0: warning: macro "REM1" is not used [-Wunused-macros]
```
```
/Users/runner/work/curl/curl/lib/parsedate.c:103:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  103 | #define PARSEDATE_SOONER 2
      |         ^
1 warning generated.
```
https://github.com/curl/curl/actions/runs/13232157963/job/36930964574?pr=16279#step:11:111
`SSLEAY_VERSION_NUMBER` is pending deletion in a separate PR.

Curious `OPENSSL_HAS_PROVIDERS` and `HAVE_ERR_REMOVE_THREAD_STATE`. No clear fix?

```
/Users/runner/work/curl/curl/lib/vtls/openssl.c:110:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  110 | #define OPENSSL_HAS_PROVIDERS
      |         ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:141:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  141 | #define HAVE_ERR_REMOVE_THREAD_STATE 1
      |         ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:147:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  147 | #define SSLEAY_VERSION_NUMBER OPENSSL_VERSION_NUMBER
      |         ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:158:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  158 | #define ARG2_X509_signature_print
      |         ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:859:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  859 | #define RAND_LOAD_LENGTH 1024
      |         ^
5 warnings generated.
```
https://github.com/curl/curl/actions/runs/13232249007/job/36931188045?pr=16279#step:11:195

Fixing this isn't pracitcal.
The `CM clang OpenSSL AppleIDN clang-tidy +examples` job is finding
further cases, and due to clang-tidy it flags them as errors and
fails on the first one. I stopped cleaning up at `openssl.c` when
bumping into these non-trivial cases to silence:

```
/Users/runner/work/curl/curl/lib/vtls/openssl.c:110:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  110 | #define OPENSSL_HAS_PROVIDERS
      |         ^
/Users/runner/work/curl/curl/lib/vtls/openssl.c:141:9: error: macro is not used [clang-diagnostic-unused-macros,-warnings-as-errors]
  141 | #define HAVE_ERR_REMOVE_THREAD_STATE
      |         ^
```
https://github.com/curl/curl/actions/runs/13232573832/job/36932009939?pr=16279#step:11:195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant