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

Create rule S7129: String literal should not be assigned to mutable char pointers (CPP-5659) #4422

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

You can preview this rule here (updated a few minutes after each push).

Review

A dedicated reviewer checked the rule description successfully for:

  • logical errors and incorrect information
  • information gaps and missing content
  • text style and tone
  • PR summary and labels follow the guidelines

@github-actions github-actions bot added the cfamily C / C++ / Objective-C label Oct 15, 2024
@frederic-tingaud-sonarsource frederic-tingaud-sonarsource changed the title Create rule S7129 Create rule S7129: String literal should not be assigned to mutable char pointers Oct 15, 2024
@frederic-tingaud-sonarsource frederic-tingaud-sonarsource marked this pull request as ready for review October 16, 2024 15:05
Copy link
Contributor

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 Show resolved Hide resolved
rules/S7129/cfamily/rule.adoc Show resolved Hide resolved

== How to fix it

=== {cpp}

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++

std::string s = "Hello world!"; // Compliant, mutable
----

=== C

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++)

mutate(s);
----

Or on the heap with `strdup`, in which case it will need to be ``free``d afterward:

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

@tomasz-kaminski-sonarsource tomasz-kaminski-sonarsource changed the title Create rule S7129: String literal should not be assigned to mutable char pointers Create rule S7129: String literal should not be assigned to mutable char pointers (CPP-5659) Oct 17, 2024
Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cfamily C / C++ / Objective-C
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants