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

Add const to string parameters #878

Merged
merged 1 commit into from
Oct 19, 2021
Merged

Add const to string parameters #878

merged 1 commit into from
Oct 19, 2021

Conversation

ataffanel
Copy link
Member

If a function does not modify its string input, it should be declared const so that the api user knows that the string will not be modified (it can be static) and to make the compiler check that we are not modifying the strings.

This PR adds const everywhere I could find it was needed.

Copy link
Contributor

@jonasdn jonasdn left a comment

Choose a reason for hiding this comment

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

Looks great!

Do we have all relevant gcc warnings enabled about breaking const qualification?

@ataffanel
Copy link
Member Author

Do we have all relevant gcc warnings enabled about breaking const qualification?

Yes I just tested and trying to modify const strings end up with an error:

  CC    log.o
.//src/modules/src/log.c: In function 'logGetVarId':
.//src/modules/src/log.c:980:11: error: assignment of read-only location '*name'
  980 |   name[0] = 1;
      |           ^
.//src/modules/src/log.c: At top level:
cc1: error: unrecognized command line option '-Wno-stringop-overread' [-Werror]
cc1: all warnings being treated as errors
make[1]: *** [tools/make/targets.mk:27: log.o] Error 1

@ataffanel ataffanel merged commit b1331c6 into master Oct 19, 2021
@ataffanel ataffanel deleted the ataffanel/const_strings branch October 19, 2021 12:34
@knmcguire knmcguire added this to the next release milestone Dec 16, 2021
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.

3 participants