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

Plumed h for gromacs #1105

Merged
merged 4 commits into from
Oct 10, 2024
Merged

Conversation

Iximiel
Copy link
Member

@Iximiel Iximiel commented Aug 7, 2024

Description

While trying to add a plumed module to gromacs I got a few -Wstringop-truncation warnings
with this PR I am trying to address them in a way that does not imply too many changes in the original plumed codebase.

I am starting this as a draft because likely this branch will get some more commit


the changes in the tests are to make the compiler complain about the tested code and not the code of the test.

Target release

I would like my code to appear in release 2.10

Type of contribution
  • changes to code or doc authored by PLUMED developers, or additions of code in the core or within the default modules
  • changes to a module not authored by you
  • new module contribution or edit of a module authored by you
Copyright
  • I agree to transfer the copyright of the code I have written to the PLUMED developers or to the author of the code I am modifying.
  • the module I added or modified contains a COPYRIGHT file with the correct license information. Code should be released under an open source license. I also used the command cd src && ./header.sh mymodulename in order to make sure the headers of the module are correct.
Tests
  • I added a new regtest or modified an existing regtest to validate my changes.
  • I verified that all regtests are passed successfully on GitHub Actions.

Comment on lines 2348 to +2349
this->msg[0]='\0';
__PLUMED_WRAPPER_STD strncat(this->msg,msg,__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1);
__PLUMED_WRAPPER_STD strncpy(this->msg,msg,__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER);
Copy link
Member Author

Choose a reason for hiding this comment

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

since this starts with this->msg[0]='\0';, I think that, only in this case, strncpy should work exactly like strncat

removing the "-1" ensures that the warning is gone

@@ -3831,7 +3831,7 @@ void* plumed_attempt_dlopen(const char*path,int mode) {
__PLUMED_FPRINTF(stderr,"+++ Allocation error +++\n");
__PLUMED_WRAPPER_STD abort();
}
__PLUMED_WRAPPER_STD strncpy(pathcopy,path,strlenpath+1);
__PLUMED_WRAPPER_STD strcpy(pathcopy,path);
Copy link
Member Author

Choose a reason for hiding this comment

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

The ideal would be strdup, but it is not ansi C (actually is c23, from my understanding)

the +1 on the length with strncpy activates the warning about an overflow

by reading the manual strcpy copies the whole string plus the \0.

@carlocamilloni
Copy link
Member

carlocamilloni commented Oct 9, 2024

@Iximiel isn't this ready for merging? maybe it should target v2.10

@Iximiel
Copy link
Member Author

Iximiel commented Oct 9, 2024

It should aim 2.10, that was 'master' at time of setting this up, I am changing it

Before readying this for merging it I was waiting for some comments

@Iximiel Iximiel changed the base branch from master to v2.10 October 9, 2024 14:07
@Iximiel Iximiel marked this pull request as ready for review October 10, 2024 06:39
@carlocamilloni carlocamilloni merged commit 0ddd460 into plumed:v2.10 Oct 10, 2024
22 checks passed
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.

2 participants