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

MONGOCRYPT-783 address C99 standard conformance warnings #973

Merged
merged 17 commits into from
Feb 28, 2025

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Feb 28, 2025

Related to MONGOCRYPT-783.

Addresses the following C standard conformance warnings for libmongocrypt:

  • Clang:
    • -Wgnu-zero-variadic-macro-arguments: 13 unique, 2,741 total.
    • -Wnewline-eof: 41 unique, 803 total.
    • -Wpedantic for object <-> function pointer conversion: 13 unique, 27 total.
    • -Wextra-semi: 1 unique, 1 total.
  • GCC:
    • -Wpedantic for __FUNCTION__: 27 unique, 19,974 total.
    • -Wpedantic for object <-> function pointer conversions: 3 unique, 29 total.
    • -Wpedantic for stray semicolon outside a function: 1 unique, 1 total.

Remaining -Wpedantic warnings concerning anonymous structs and unions are addressed by #972.


Most object <-> function pointer conversion warnings are concerned with specifying symbols which are loaded dynamically, as underlying functions require use of void* even for function symbols. The mcr_dll_sym function was split into an *_obj and *_fn variant accordingly so that the object -> function pointer cast can be isolated to mcr_dll_sym_fn. Other instances of such casts are converted into instances of -Wcast-strict-function-type Clang warnings (-Wpedantic for GCC) which are silenced using the new MC_(BEGIN|END)_CAST_FUNCTION_TYPE_STRICT_IGNORE macros.


-Wgnu-zero-variadic-macro-arguments Clang warnings were introduced by #759. Most are easily addressed by deferring the enforcement of a format string argument to the underlying function being invoked (e.g. _mongocrypt_set_error). The -Wvariadic-macro-arguments-omitted warning is added to ENABLE_MORE_WARNINGS_AS_ERRORS to further enforce at-least-one-argument-to-... standard conformance. Reverted due to overlooking compiler compatibility for this warning flag.

The CLIENT_ERR_PREFIXED macro in mc-rangeopts.c required the most effort to address -Wgnu-zero-variadic-macro-arguments warnings. The CLIENT_ERR_PREFIXED (which is impossible to implement in a conforming manner) was instead replaced with a direct call to CLIENT_ERR with an explicit prefix of the ERROR_PREFIX macro before the error message strings.

@eramongodb eramongodb requested a review from kevinAlbs February 28, 2025 17:16
@eramongodb eramongodb self-assigned this Feb 28, 2025
@kevinAlbs kevinAlbs requested review from mdbmes and removed request for kevinAlbs February 28, 2025 18:52
@@ -66,7 +63,7 @@ void mc_FLE2EncryptionPlaceholder_init(mc_FLE2EncryptionPlaceholder_t *placehold
memset(placeholder, 0, sizeof(mc_FLE2EncryptionPlaceholder_t));
}

#define ERROR_PREFIX "Error parsing FLE2EncryptionPlaceholder"
#define ERROR_PREFIX "Error parsing FLE2EncryptionPlaceholder: "
Copy link

Choose a reason for hiding this comment

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

It looks like the extra ": " is missing from all of the ERROR_PREFIX except for this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Thank you!

@eramongodb eramongodb requested a review from mdbmes February 28, 2025 20:26
Copy link

@mdbmes mdbmes left a comment

Choose a reason for hiding this comment

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

Minor issue, looks like the extra ": " made it into mc-rangeopts.c but not mc-fle2-encryption-placeholder.c. Everything else looks good!

@eramongodb eramongodb merged commit 8270531 into mongodb:master Feb 28, 2025
45 of 46 checks passed
@eramongodb eramongodb deleted the crypt-783-pedantic branch February 28, 2025 21:49
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.

2 participants