netcdf suggestions (o.a. tempnam / rename problem)

I've mailed this to netcdf a while ago and heard nothing ever since.
Because it mentions the tempnam / rename problem with a solution
I mail it to the group.

The other two bugs might not show up on all systems.

Manfred.

--------------------------------------------------------------------------------
While running the tests I discovered a few bugs:

1.      In ncgen/ncgen.l the following code is executed to find
        out whether the variable fits in a long or not:

            if (dd == (double) (long) dd)
        
        Unfortunately under UNIX this results in a Float Point Exception
        when the value doesn't fit in a long anymore !!

        Alternatively this could be done using:

            #include <limits.h>

            if (dd >= LONG_MIN  &&  dd <= LONG_MAX)

        Which is more portable.

2.      src/file.c function ncredef
            Here is (sometimes) the function tempnam used to generate a 
            temporary pathname.
        src/file.c function NC_endef
            Here is the rename system call used to move the temporary
            file to its original location.

        Rename only works when the two files are on the same file system.
        The programmer anticipated this by using the result from getcwd as
        path argument to tempnam. However, the environment variable TMPDIR
        has precedence over the path specified in the code.
        (See also the comment about unicos in the source file,
        this might have been TMPDIR)

        Instead of trying tempnam/tmpnam you better use mktemp(3C):

            char        scratchbuf[FILENAME_MAX + 1];

            scratchfile = mktemp(strcpy(scratchbuf, "nc.XXXXXX"));

        We need a scratchbuf because mktemp modifies its argument which
        would dump core if literal strings are read-only and would restrict
        the use to a single call because after the first call all following
        calls would result in the same file name.

3.      The use of FILENAME_MAX for path name storage.
        FILENAME_MAX is defined in stdio.h as the maximum length of a FILE name,
        not a PATH name. On a System V file system this is only 14 characters !
        Although a strncpy is performed this will loose most of the path name
        if non-local files are used. This will results in errors when the
        path name is used to open / rename / remove the file.

--------------------------------------------------------------------------------
Manfred Brands                   O'Toole's commentary on Murphy's Law:
Murphy Software B.V.                 "Murphy was an optimist."
Current Email: mb@xxxxxxxxxxx
--------------------------------------------------------------------------------


  • 1992 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: