Skip to content

Commit

Permalink
Plumed h for gromacs (plumed#1105)
Browse files Browse the repository at this point in the history
* now the warnings from this test comes only from Plumed.h

* change ncat to ncpt and looks like there are no more warnings

* mimickying strdup to avoid a -Wstringop-overflow warning

* trying with memcpy to avoid the security warning
  • Loading branch information
Iximiel authored Oct 10, 2024
1 parent 48d9562 commit 0ddd460
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions regtest/basic/rt-make-exceptions/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(){
int natoms=10;

std::vector<double> positions(3*natoms,0.0);
for(unsigned i=0;i<3*natoms;i++) positions[i]=i;
for(int i=0;i<3*natoms;i++) positions[i]=i;
std::vector<double> masses(natoms,1.0);
std::vector<double> forces(3*natoms,0.0);
std::vector<double> box(9,0.0);
Expand Down Expand Up @@ -145,7 +145,7 @@ int main(){
plumed.cmd("setVirial",&virial[0]);
plumed.cmd("setMasses",&masses[0]);
// set positions after having passed the pointer. They should be accessed here (at "calc").
for(unsigned i=0;i<3*natoms;i++) positions[i]=i*step;
for(int i=0;i<3*natoms;i++) positions[i]=i*step;
plumed.cmd("calc");

// this should fail
Expand Down
4 changes: 2 additions & 2 deletions src/wrapper/Plumed.h
Original file line number Diff line number Diff line change
Expand Up @@ -2346,7 +2346,7 @@ class Plumed {
char msg[__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER];
void init(const char* msg) __PLUMED_WRAPPER_CXX_NOEXCEPT {
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);
this->msg[__PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1]='\0';
if(PlumedGetenvExceptionsDebug() && __PLUMED_WRAPPER_STD strlen(msg) > __PLUMED_WRAPPER_CXX_EXCEPTION_BUFFER-1) __PLUMED_WRAPPER_STD fprintf(stderr,"+++ WARNING: message will be truncated\n");
}
Expand Down Expand Up @@ -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 memcpy(pathcopy,path,strlenpath+1);
pc=pathcopy+strlenpath-6;
while(pc>=pathcopy && __PLUMED_WRAPPER_STD memcmp(pc,"Kernel",6)) pc--;
if(pc>=pathcopy) {
Expand Down

0 comments on commit 0ddd460

Please sign in to comment.