Bug in MeshMoverLinearVariable

Submitted by R Schubert on Mon, 11/02/2015 - 15:03

The constructor of MeshMoverLinearVariable (mesh_mover.cpp:117) starts

int n;
n = strlen(&var1[2]) + 1;
var1str_ = new char[n];
strcpy(var1str_,&var1[2]);
myvar1_ = input->variable->find(var1str_);

n = strlen(&var1[2]) + 1;
var2str_ = new char[n];
strcpy(var2str_,&var2[2]);
myvar2_ = input->variable->find(var2str_);

n = strlen(&var1[2]) + 1;
var3str_ = new char[n];
strcpy(var3str_,&var3[2]);
myvar3_ = input->variable->find(var3str_);

The first assignment to n is okay, the second and third introduce undefined behavior, which caused my simulation to abort upon unfixing. The correct code should read:

int n;
n = strlen(&var1[2]) + 1;
var1str_ = new char[n];
strcpy(var1str_,&var1[2]);
myvar1_ = input->variable->find(var1str_);

n = strlen(&var2[2]) + 1;
var2str_ = new char[n];
strcpy(var2str_,&var2[2]);
myvar2_ = input->variable->find(var2str_);

n = strlen(&var3[2]) + 1;
var3str_ = new char[n];
strcpy(var3str_,&var3[2]);
myvar3_ = input->variable->find(var3str_);

ckloss's picture

ckloss | Thu, 12/10/2015 - 21:52

Hi Raphael,

thanks a lot! very good catch :-) will be fixed in the next release!

Best wishes
Christoph