Skip to content

Commit ffb148d

Browse files
committed
Report error if any supplied bound/index is zero or negative
1 parent 3f1244e commit ffb148d

10 files changed

+34
-19
lines changed

dat1.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ dat1ExportDims( int ndims, const hsize_t h5dims[], hdsdim hdsdims[],
286286
int *status );
287287

288288
void
289-
dat1ImportDims( int ndims, const hdsdim hdsdims[], hsize_t h5dims[],
290-
int *status );
289+
dat1ImportDims( const char *func, int ndims, const hdsdim hdsdims[],
290+
hsize_t h5dims[], int *status );
291291

292292
char *
293293
dat1GetFullName( hid_t objid, int asfile, ssize_t * namlen, int *status);

dat1ImportDims.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
* Library routine
1414
1515
* Invocation:
16-
* void dat1ImportDims( int ndims, const hdsdim hdsdims[], hsize_t h5dims[],
17-
* int * status );
16+
* void dat1ImportDims( const char *func, int ndims, const hdsdim hdsdims[],
17+
* hsize_t h5dims[], int * status );
1818
1919
* Arguments:
20+
* func = const char * (Given)
21+
* The name of the calling function, for use in error messages.
2022
* ndims = int (Given)
2123
* Number of dimensions to import.
2224
* hdsdims = const hdsdim[] (Given)
23-
* Dimensions to import. Only ndims will be accessed.
25+
* Dimensions to import. Only ndims will be accessed. These are
26+
* 1-based indices.
2427
* h5dims = hsize_t [] (Returned)
2528
* Array to receive imported dimensions. Must be at least ndims in size.
2629
* status = int* (Given and Returned)
@@ -32,7 +35,8 @@
3235
3336
* Authors:
3437
* TIMJ: Tim Jenness (Cornell)
35-
* {enter_new_authors_here}
38+
* DSB: David S Berry (EAO)
39+
{enter_new_authors_here}
3640
3741
* Notes:
3842
* - Does not assume that hdsdim and hsize_t are the same type.
@@ -42,6 +46,8 @@
4246
* History:
4347
* 2014-09-03 (TIMJ):
4448
* Initial version
49+
* 2019-02-14 (DSB):
50+
* Report error if any supplied index is less than or equal to zero.
4551
* {enter_further_changes_here}
4652
4753
* Copyright:
@@ -92,20 +98,29 @@
9298

9399
#include "hds1.h"
94100
#include "dat1.h"
101+
#include "dat_err.h"
95102
#include "hds.h"
96103

97104
void
98-
dat1ImportDims( int ndims, const hdsdim hdsdims[], hsize_t h5dims[],
99-
int *status ) {
105+
dat1ImportDims( const char *func, int ndims, const hdsdim hdsdims[],
106+
hsize_t h5dims[], int *status ) {
100107
int i;
101108

102109
if (*status != SAI__OK) return;
103110
if (ndims == 0) return;
104111

105112
/* We have to transpose these dimensions */
106113
for (i=0; i<ndims; i++) {
107-
int oposn = ndims - 1 - i;
108-
h5dims[oposn] = hdsdims[i];
114+
if( hdsdims[ i ] <= 0 ) {
115+
*status = DAT__SUBIN;
116+
emsRepf( " ", "%s: Illegal subscript (%" HDS_DIM_FORMAT
117+
") for dimension %d", status, func, hdsdims[ i ],
118+
i );
119+
break;
120+
} else {
121+
int oposn = ndims - 1 - i;
122+
h5dims[oposn] = hdsdims[i];
123+
}
109124
}
110125
return;
111126
}

dat1New.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ dat1New( const HDSLoc *locator,
151151
if (*status != SAI__OK) return NULL;
152152

153153
/* Copy dimensions if appropriate */
154-
dat1ImportDims( ndim, dims, h5dims, status );
154+
dat1ImportDims( "dat1New", ndim, dims, h5dims, status );
155155

156156
/* Work out where to place the component */
157157
place = dat1RetrieveContainer( locator, status );

datAlter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ datAlter( HDSLoc *locator, int ndim, const hdsdim dims[], int *status) {
247247
herr_t h5err;
248248

249249
/* Copy dimensions and reorder */
250-
dat1ImportDims( ndim, dims, h5dims, status );
250+
dat1ImportDims( "datAlter", ndim, dims, h5dims, status );
251251

252252
/* First we simply try the native resize. This will only work
253253
if the system is using chunked storage and the registered

datCell.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ datCell(const HDSLoc *locator1, int ndim, const hdsdim subs[],
119119
datName(locator1, namestr, status );
120120

121121
/* Copy dimensions if appropriate */
122-
dat1ImportDims( ndim, subs, h5subs, status );
122+
dat1ImportDims( "datCell", ndim, subs, h5subs, status );
123123

124124
isstruct = dat1IsStructure( locator1, status );
125125

datGet.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ datGet(const HDSLoc *locator, const char *type_str, int ndim,
235235
}
236236

237237
/* Copy dimensions if appropriate */
238-
dat1ImportDims( ndim, dims, h5dims, status );
238+
dat1ImportDims( "datGet", ndim, dims, h5dims, status );
239239

240240
/* Create a memory dataspace for the incoming data */
241241
CALLHDFE( hid_t, mem_dataspace_id,

datPut.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ datPut( const HDSLoc *locator, const char *type_str, int ndim, const hdsdim dims
244244
}
245245

246246
/* Copy dimensions if appropriate */
247-
dat1ImportDims( ndim, dims, h5dims, status );
247+
dat1ImportDims( "datPut", ndim, dims, h5dims, status );
248248

249249
/* Create a memory dataspace for the incoming data */
250250
CALLHDFE( hid_t, mem_dataspace_id,

datSlice.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ datSlice(const HDSLoc *locator1, int ndim, const hdsdim lower[],
207207
}
208208

209209
/* Import the bounds. */
210-
dat1ImportDims( ndim, loc2lower, h5lower, status );
211-
dat1ImportDims( ndim, loc2upper, h5upper, status );
212-
dat1ImportDims( ndim, loc1dims, h5dims, status );
210+
dat1ImportDims( "datSlice (lower)", ndim, loc2lower, h5lower, status );
211+
dat1ImportDims( "datSlice (upper)", ndim, loc2upper, h5upper, status );
212+
dat1ImportDims( "datSlice", ndim, loc1dims, h5dims, status );
213213

214214
/* Clone the locator and modify its dataspace */
215215
datClone( locator1, &sliceloc, status );

hdsNew.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ hdsNew(const char *file_str,
149149
if (*status != SAI__OK) return *status;
150150

151151
/* Copy dimensions if appropriate */
152-
dat1ImportDims( ndim, dims, h5dims, status );
152+
dat1ImportDims( "hdsNew", ndim, dims, h5dims, status );
153153

154154
/* Convert the HDS data type to HDF5 data type as an early sanity
155155
check. */

make-hds-types.c

100755100644
File mode changed.

0 commit comments

Comments
 (0)