-
Notifications
You must be signed in to change notification settings - Fork 297
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
Plumed h for gromacs #1105
Conversation
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); |
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.
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
src/wrapper/Plumed.h
Outdated
@@ -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); |
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.
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
.
@Iximiel isn't this ready for merging? maybe it should target v2.10 |
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 |
Description
While trying to add a plumed module to gromacs I got a few
-Wstringop-truncation
warningswith 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
Copyright
COPYRIGHT
file with the correct license information. Code should be released under an open source license. I also used the commandcd src && ./header.sh mymodulename
in order to make sure the headers of the module are correct.Tests