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

util.c: assert that format strings are not empty #22378

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ S_maybe_protect_ro(pTHX_ struct perl_memory_debug_header *header)
# endif
#endif

/* Sanity check: Format strings must not be empty */
STATIC_ASSERT_DECL(sizeof I32df > 1);
STATIC_ASSERT_DECL(sizeof U32of > 1);
STATIC_ASSERT_DECL(sizeof U32uf > 1);
STATIC_ASSERT_DECL(sizeof U32xf > 1);
STATIC_ASSERT_DECL(sizeof U32Xf > 1);
STATIC_ASSERT_DECL(sizeof IVdf > 1);
STATIC_ASSERT_DECL(sizeof UVuf > 1);
STATIC_ASSERT_DECL(sizeof UVof > 1);
STATIC_ASSERT_DECL(sizeof UVxf > 1);
STATIC_ASSERT_DECL(sizeof UVXf > 1);
STATIC_ASSERT_DECL(sizeof NVef > 1);
STATIC_ASSERT_DECL(sizeof NVff > 1);
STATIC_ASSERT_DECL(sizeof NVgf > 1);
STATIC_ASSERT_DECL(sizeof Gid_t_f > 1);
STATIC_ASSERT_DECL(sizeof Uid_t_f > 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these be placed in a loop? Could they be alphabetized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could these be placed in a loop?

No, C doesn't do that kind of metaprogramming.

Could they be alphabetized?

Yes, but the current order matches the order of symbols in config.h. Which would be more useful?


/*
=for apidoc_section $memory
=for apidoc safesysmalloc
Expand Down