Skip to content

openc: Add missing terminator to filename strings

I found that Pede would intermittently (~75% of the time) fail to open the data files, with an error like this:

 initc: using zlib version 1.2.12
 Open error for file mille-data-0.bin           2
 Open error for file mille-data-1.bin           2
 Open error for file mille-data-2.bin           2
STOP FILETC: open error   

Adding some diagnostics to openc() in readc.c:

 #ifdef USE_ZLIB
+                printf("gzopen('%s')\n", fileName);
                 files[fileIndex] = gzopen(fileName, "rb");

Shows what looks like unterminated strings:

 initc: using zlib version 1.2.12
gzopen('mille-data-0.bin�&���')
 Open error for file mille-data-0.bin           2
gzopen('mille-data-1.bin�&���')
 Open error for file mille-data-1.bin           2
gzopen('mille-data-2.bin�&���')
 Open error for file mille-data-2.bin           2
STOP FILETC: open error                                      

This commit adds the missing terminators. I chose to do it from C by passing the length of the string through to openc, though I think it could also be done on the Fortran side with an equivalent amount of hassle. I wrote an explicit loop to copy the string, to avoid adding another #include.

The old cfortran.h seemed to handle this correctly, so the bug was introduced about a month ago by 3a4b3e0c.

Merge request reports

Loading