Skip to content

Commit 71e2bd8

Browse files
ferdymercuryguitargeek
authored andcommitted
[h2root] occassional memory corruption issue stems from substring replacement
by adding a space, we create an extra char that will be substituted by c, rather than appending to the string
1 parent 9efafcd commit 71e2bd8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

main/src/h2root.cxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ int main(int argc, char **argv)
312312

313313
int lun = 10;
314314
#ifndef WIN32
315-
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("px"),record_size,ier,7,strlen(file_in),2);
315+
// "px" is a string being changed to "pxc" in the fortran side; since it's a temporary on C's side,
316+
// we need a buffer of at least 3 chars on Cs side, too. Predefine it as a extra variable "px " since that way
317+
// the space will be replaced by 'c' on the preallocated memory, instead of appending a new char (new memory) to "px".
318+
auto opt = PASSCHAR("px ");
319+
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),opt,record_size,ier,7,strlen(file_in),2);
316320
#else
317321
hropen(lun,PASSCHAR("example"),PASSCHAR(file_in),PASSCHAR("px"),record_size,ier);
318322
#endif

0 commit comments

Comments
 (0)