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

Conversation

mauke
Copy link
Contributor

@mauke mauke commented Jul 4, 2024

If any of these format strings are empty, things can go very wrong at runtime, from garbage output to segfaults (e.g. see #22375).

This is a static check, so it could be placed in any source file. I chose util.c because according to the comment at the top, it is the home of "any stuff that people couldn't think of a better place for".

If any of these format strings are empty, things can go very wrong at
runtime, from garbage output to segfaults (e.g. see Perl#22375).

This is a static check, so it could be placed in any source file. I
chose util.c because according to the comment at the top, it is the home
of "any stuff that people couldn't think of a better place for".
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?

@mauke mauke merged commit c5df4fd into Perl:blead Jul 5, 2024
30 checks passed
@mauke mauke deleted the assert-fmt-strings-nonempty branch July 5, 2024 23:23
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.

None yet

3 participants