-
Notifications
You must be signed in to change notification settings - Fork 29
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
Create rule S7129: String literal should not be assigned to mutable char pointers (CPP-5659) #4422
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like split on How to fix it between C and C++. The C solution are pretty valid and less impacting solution, available in C++, and I would like to just make it const.
I would personally merge the How to fix
it. and have std::string_view
as extra mile for C++.
Similarry, I would mention std::string
and strdup
as last solution, requiring memory allocation in C++/.
rules/S7129/cfamily/rule.adoc
Outdated
|
||
== How to fix it | ||
|
||
=== {cpp} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename the section into using `string classes in C++
rules/S7129/cfamily/rule.adoc
Outdated
std::string s = "Hello world!"; // Compliant, mutable | ||
---- | ||
|
||
=== C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the section:
== Keeping c-string usages (C, C++)
rules/S7129/cfamily/rule.adoc
Outdated
mutate(s); | ||
---- | ||
|
||
Or on the heap with `strdup`, in which case it will need to be ``free``d afterward: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have this in pitfall section about reentracy when using static
.
Would also add the line after example with free, that std::strign
does that automaticall.y
Quality Gate passed for 'rspec-frontend'Issues Measures |
Quality Gate passed for 'rspec-tools'Issues Measures |
Quality Gate passed for 'rspec-tools'Issues Measures |
Quality Gate passed for 'rspec-frontend'Issues Measures |
You can preview this rule here (updated a few minutes after each push).
Review
A dedicated reviewer checked the rule description successfully for: