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

Use strmake over my_snprintf to copy strings #3429

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ParadoxV5
Copy link
Contributor

@ParadoxV5 ParadoxV5 commented Jul 28, 2024

Description

What problem is the patch trying to solve?

There is no need to parse a format string if we just need to clone chars over (and truncate if the buffer overflows).
In fact, when #3360 enabled ATTRIBUTE_FORMAT on my_snprintf, -Werror=format-security complained several of these that “format not a string literal and no format arguments”.

There are alternatives to strmake, but I’ve determined on Zulip chat for #3360 that strmake is the best fit.
(Although, in one case, strcpy suffices because it’s the first write to the buffer and will countably not overflow.)

Do you think this patch might introduce side-effects in other parts of the server?

Unless I messed up – not at all? I just swapped function A with function B.

Release Notes

Um… General code cleanup?

How can this PR be tested?

This switch does not require new tests – existing tests will do.

Basing the PR against the correct MariaDB version

  • This is a new feature or a refactoring, and the PR is based against the latest MariaDB development branch.
    • Uh, I suppose this is a refactoring.
  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.

PR quality check

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@@ -66,7 +66,7 @@ int Xcurl(PGLOBAL g, PCSZ Http, PCSZ Uri, PCSZ filename)
my_snprintf(buf, sizeof(buf)-1, "%s/%s", Http, Uri);

} else
my_snprintf(buf, sizeof(buf)-1, "%s", Http);
strmake(buf, Http, sizeof(buf)-2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

questionable double--1

There is no need to parse a format string if we just need to clone
chars over. In fact, when MariaDB#3360 enabled `ATTRIBUTE_FORMAT` on
`my_snprintf`, `-Werror=format-security` complained several of
these that “format not a string literal and no format arguments”.
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.

1 participant