severity 489886 minor tags 489886 - help retitle 489886 cfortran: invalid strcpy in example code snippet fd/fd.c thanks
Hi Jean-Guillaume, first, sorry for taking so long to get back to you. As best I can tell after making a detailed inspection, the bug you reported at http://bugs.debian.org/489886 seems to be a problem in the cfortran example code snippet "fd/fd.c", not in the cfortran.h header itself. I'm therefore retitling the bug appropriately and downgrading the severity to "minor". If you have more examples showing a problem in cfortran.h itself I'll be happy to reconsider. I ran gcc as you did, plus an additional "-save-temps" option, on fd.c, cleaned up the resulting preprocessed file a little bit, and added some more debugging printf's. From that I deciphered what's happening: The original string ii, "happy ", has 12 bytes including the trailing zero byte. It gets passed into FORTRAN together with the string length (11). In FORTRAN subroutine fd(), the contents of the string are changed to "birthday " but the address of the string is the same. This address and the same string length is then passed into the cfortran-generated C function cdcfort_, which mallocs an array of size 11+1 == 12 and copies in the other string's contents (deleting trailing spaces). cdcfort_() passes the newly malloced string into the cd() function. cd() then tries to strcpy the string "to you 12345678", length 16 bytes, into it. This is the real problem. For whatever reason, there is no crash until the call to free(), which detects corrupted memory. (Valgrind detects the error where it first happens.) If I add four more spaces at the end of the definition of "ii" in main(), there is no crash and valgrind does not complain. So to summarize, if this piece of example code ever worked, it only did so by accident. I can add four more spaces in ii to prevent the crash, but I don't know what the original pedagogical intent of the example program was, so I can't necessarily make it work how it was supposed to. Burkhard, do you happen to remember what the intended output was? best regards, -- Kevin B. McCarty <[EMAIL PROTECTED]> WWW: http://www.starplot.org/ WWW: http://people.debian.org/~kmccarty/ GPG: public key ID 4F83C751
signature.asc
Description: OpenPGP digital signature