Skip to content

ncput uses incorrect cast of pointer on windows #121

@simonbyrne

Description

@simonbyrne

While testing TempestRemap (using the BinaryBuilder builds) on Windows, @juliasloan25 came across the following error (https://github.com/CliMA/ClimaLSM.jl/actions/runs/7147032075/job/19465822084#step:6:528)

  ....EXCEPTION (../src/OfflineMap.cpp, Line 2438) Error writing to NetCDF file (-57)

This points to this line:
https://github.com/ClimateGlobalChange/tempestremap/blob/v2.2.0/src/OfflineMap.cpp#L2438

and error -57
https://github.com/Unidata/netcdf-c/blob/c2fd38d5d2c69b6e975a34409c5f90c6e126973b/docs/all-error-codes.md#L34

Edge+start exceeds dimension bound

I suspect the error is due to the definition of ncput:

tempestremap/src/netcdf.cpp

Lines 1116 to 1127 in 6f1b783

NcBool NcVar::put( const TYPE* vals, const long* count ) \
{ \
/* no need to check type() vs. TYPE, invoked C function will do that */ \
if (! the_file->data_mode()) \
return FALSE; \
size_t start[NC_MAX_DIMS]; \
for (int i = 0; i < num_dims(); i++) \
start[i] = the_cur[i]; \
return NcError::set_err( \
makename2(nc_put_vara_,NCTYPE) (the_file->id(), the_id, start, (const size_t *) count, vals) \
) == NC_NOERR; \
}

which casts a long* to a size_t*: on Windows long is only 32 bit, but size_t is 64 bit. Since it is casting the pointer, not a value, NetCDF will attempt to dereference the pointer looking for a 64-bit value, so will presumably get the wrong result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions