[MINC-development] patches for tmpnam

Peter NEELIN minc-development@bic.mni.mcgill.ca
Sun, 9 Mar 2003 16:58:27 -0500


On Fri, 7 Mar 2003, Robert VINCENT wrote:

> a peep from the linker.  Does anyone want to review these changes in
> detail before I commit them?  Is there a preferred way to distribute the
> changes for review, or do folks just want to examine them in
> ~bert/projects/minc/cvsroot/minc (which should be world-readable).

If you attach a patch, all readers of the list should be able to see the
changes fairly easily. Providing a BIC-specific location as well may be
helpful for those who like to see the whole source. Note that you should
use diff -u format for the patches.

The patches look good, except for a few minor things:

 - The default values of P_tmpdir should be "/var/tmp".
 - Watch those strn* functions - they do not append '\0' if they truncate,
   so you have to do it yourself after every call (or before, and remember
   to decrement n by 1 first).
 - Watch strncat - according to the irix man page it limits the number of
   characters appended to n, so you need to decrement your limit by the
   number of characters already in the string.
 - When you call tmpnam, you don't check that tmpfile_len is at least
   L_tmpnam, so it could overrun. You could pass NULL and then strncpy
   the result. However,
 - If the user buffer is too short, would it not make sense to return an
   error rather than a truncated file name? I don't know what
   mkstemp does with fewer than six X's. Your comments should
   probably suggest that the caller allocate a buffer of PATH_MAX+1
   characters to be certain that failure does not occur (since TMPDIR can
   change the length at run time).

You seem to have covered all of our previously expressed concerns however
(compiler warnings, leaking file descriptors, using TMPDIR) as well as
dealing with systems that are missing mkstemp (do we know of any?).
Thanks.

             Peter
----
             Peter Neelin (neelin@bic.mni.mcgill.ca)