Broken error handling in function gmx_tmpnam
The "gmx_tmpnam" function used for temporary file creation does error handling by comparing the file descriptor returned by the C library function "mkstemp" to some of the possible codes that are actually stored in the "errno" global variable. This will not catch any error, and will cause a spurious error when the file handle happens to have the same value as one of the error codes. I noticed this because it broke "gmx do_dssp" given some combination of compiler and Gromacs versions; "do_dssp" would then complain "Permission denied" when the file was actually created without problem.
IO error handling in C should generally be done by checking the validity of the file descriptor. The error code can then be used to provide an informative message. I attach a patch that fixes "gmx_tmpnam", but I have not checked if other functions are affected.
Fix error handling in gmx_tmpnam
The return code of mkstemp was being mis-used for error handling.
This could explain some long-standing issues with (e.g.) DSSP
mysteriously not working even when the user had done everything right.
#2 Updated by Mark Abraham about 2 years ago
- Category set to core library
- Status changed from New to Fix uploaded
- Assignee set to Mark Abraham
- Target version set to 5.0.5
- Affected version - extra info set to probably every version since 37b450f33
Thanks, good catch! I uploaded your patch for code review at the above link.