More pedantically correct check

This modifies the previous change to be more pedantically correct.  It should always be an NC_EINVALCOORDS error if start exceeds fdims[2]; however, if start equals fdims[2], then it is only an error if count is non-zero.
This commit is contained in:
Greg Sjaardema 2016-04-04 08:56:08 -06:00 committed by Ward Fisher
parent 9290b31c9d
commit c7ccdfa543

View File

@ -625,7 +625,8 @@ nc4_put_vara(NC *nc, int ncid, int varid, const size_t *startp,
assert(dim && dim->dimid == var->dimids[d2]);
if (!dim->unlimited)
{
if (start[d2] >= (hssize_t)fdims[d2] && count[d2] > 0)
if (start[d2] > (hssize_t)fdims[d2] ||
(start[d2] == (hssize_t)fdims[d2] && count[d2] > 0))
BAIL_QUIET(NC_EINVALCOORDS);
if (start[d2] + count[d2] > fdims[d2])
BAIL_QUIET(NC_EEDGE);
@ -956,7 +957,8 @@ nc4_get_vara(NC *nc, int ncid, int varid, const size_t *startp,
BAIL(retval);
/* Check for out of bound requests. */
if (start[d2] >= (hssize_t)ulen && count[d2])
if (start[d2] > (hssize_t)ulen ||
(start[d2] == (hssize_t)ulen && count[d2] > 0))
BAIL_QUIET(NC_EINVALCOORDS);
if (start[d2] + count[d2] > ulen)
BAIL_QUIET(NC_EEDGE);
@ -979,7 +981,8 @@ nc4_get_vara(NC *nc, int ncid, int varid, const size_t *startp,
else
{
/* Check for out of bound requests. */
if (start[d2] >= (hssize_t)fdims[d2] && count[d2] > 0)
if (start[d2] > (hssize_t)fdims[d2] ||
(start[d2] == (hssize_t)fdims[d2] && count[d2] > 0))
BAIL_QUIET(NC_EINVALCOORDS);
if (start[d2] + count[d2] > fdims[d2])
BAIL_QUIET(NC_EEDGE);