Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncput uses incorrect cast of pointer on windows #121

Open
simonbyrne opened this issue Dec 8, 2023 · 0 comments
Open

ncput uses incorrect cast of pointer on windows #121

simonbyrne opened this issue Dec 8, 2023 · 0 comments

Comments

@simonbyrne
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant