mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
Fix non-portable test that depends on nonstandardized floating-point format using e+08, not e+008. Fixes for some problems reported in scan-build static analysis.
This commit is contained in:
parent
00e50f5a44
commit
c6f399c731
@ -88,7 +88,7 @@ main()
|
||||
if ((typeid = H5Topen(grpid, obj_name)) < 0) ERR;
|
||||
if ((class = H5Tget_class(typeid)) < 0) ERR;
|
||||
if (class != H5T_OPAQUE) ERR;
|
||||
if (!(type_size = H5Tget_size(typeid))) ERR;
|
||||
if (!(H5Tget_size(typeid))) ERR;
|
||||
}
|
||||
|
||||
/* Close everything. */
|
||||
@ -152,7 +152,7 @@ main()
|
||||
/* Once open for read only access, the file can't be opened again
|
||||
* for write access. */
|
||||
if ((fileid = H5Fopen(FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) ERR;
|
||||
if ((fileid2 = H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT)) >= 0) ERR;
|
||||
if (H5Fopen(FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT) >= 0) ERR;
|
||||
if (H5Fclose(fileid) < 0) ERR;
|
||||
|
||||
/* But you can open the file for read/write access, and then open
|
||||
|
@ -66,7 +66,9 @@ main()
|
||||
if ((class = H5Tget_class(typeid)) < 0) ERR;
|
||||
if (class != H5T_STRING) ERR;
|
||||
if (!(type_size = H5Tget_size(typeid))) ERR;
|
||||
if (type_size != sizeof(char *)) ERR;
|
||||
if ((is_str = H5Tis_variable_str(typeid)) < 0) ERR;
|
||||
if (!is_str) ERR;
|
||||
|
||||
/* Make sure this is a scalar. */
|
||||
if (H5Sget_simple_extent_type(spaceid) != H5S_SCALAR) ERR;
|
||||
|
@ -1063,7 +1063,7 @@ cdRel2Comp(cdCalenType timetype, char* relunits, double reltime, cdCompTime* com
|
||||
}
|
||||
/* Calculate new epochal time. */
|
||||
/* Convert back to human, then comptime. */
|
||||
else{
|
||||
else if(baseunits == cdHour){
|
||||
Cde2h(base_etm+delta, old_timetype, 1970, &humantime);
|
||||
|
||||
}
|
||||
|
@ -192,7 +192,6 @@ NC4_inq_dimid(int ncid, const char *name, int *idp)
|
||||
{
|
||||
if (idp)
|
||||
*idp = dim->dimid;
|
||||
finished++;
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
|
@ -802,6 +802,8 @@ get_type_info2(NC_HDF5_FILE_INFO_T *h5, hid_t datasetid,
|
||||
endianness = NC_ENDIAN_LITTLE;
|
||||
else if (order == H5T_ORDER_BE)
|
||||
endianness = NC_ENDIAN_BIG;
|
||||
else /* don't support H5T_ORDER_VAX, H5T_ORDER_MIXED, H5T_ORDER_NONE */
|
||||
return NC_EBADTYPE;
|
||||
/* Copy this into the type_info struct. */
|
||||
(*type_info)->endianness = endianness;
|
||||
}
|
||||
@ -1960,9 +1962,9 @@ nc4_rec_read_vars(NC_GRP_INFO_T *grp)
|
||||
|
||||
res = H5Literate(grp->hdf_grpid, H5_INDEX_NAME, H5_ITER_INC,
|
||||
&idx, nc4_rec_read_vars_cb, (void *)grp);
|
||||
if (res<0)
|
||||
return NC_EHDFERR;
|
||||
}
|
||||
if (res<0)
|
||||
return NC_EHDFERR;
|
||||
|
||||
/* Scan the group for global (i.e. group-level) attributes. */
|
||||
if ((retval = read_grp_atts(grp)))
|
||||
@ -2807,9 +2809,7 @@ int
|
||||
NC4__enddef(int ncid, size_t h_minfree, size_t v_align,
|
||||
size_t v_minfree, size_t r_align)
|
||||
{
|
||||
NC_FILE_INFO_T *nc;
|
||||
|
||||
if (!(nc = nc4_find_nc_file(ncid)))
|
||||
if (!nc4_find_nc_file(ncid))
|
||||
return NC_EBADID;
|
||||
|
||||
return NC4_enddef(ncid);
|
||||
@ -3151,7 +3151,6 @@ NC4_inq(int ncid, int *ndimsp, int *nvarsp, int *nattsp, int *unlimdimidp)
|
||||
if (dim->unlimited)
|
||||
{
|
||||
*unlimdimidp = dim->dimid;
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ nc4_get_hdf_typeid(NC_HDF5_FILE_INFO_T *h5, nc_type xtype,
|
||||
break;
|
||||
default:
|
||||
/* Maybe this is a user defined type? */
|
||||
if (!(retval = nc4_find_type(h5, xtype, &type)))
|
||||
if (!nc4_find_type(h5, xtype, &type))
|
||||
{
|
||||
if (!type)
|
||||
return NC_EBADTYPE;
|
||||
|
@ -122,7 +122,7 @@ find_var_shape_grp(NC_GRP_INFO_T *grp, int varid, int *ndims,
|
||||
dim in the space. */
|
||||
if ((dataset_ndims = H5Sget_simple_extent_ndims(spaceid)) < 0)
|
||||
BAIL(NC_EHDFERR);
|
||||
if (dataset_ndims != *ndims)
|
||||
if (ndims && dataset_ndims != *ndims)
|
||||
BAIL(NC_EHDFERR);
|
||||
if (!(h5dimlen = malloc(dataset_ndims * sizeof(hsize_t))))
|
||||
BAIL(NC_ENOMEM);
|
||||
|
@ -396,7 +396,7 @@ nc_def_var_nc4(int ncid, const char *name, nc_type xtype,
|
||||
|
||||
/* If this is a user defined type, find it. */
|
||||
if (xtype > NC_STRING)
|
||||
if ((retval = nc4_find_type(grp->file->nc4_info, xtype, &type_info)))
|
||||
if (nc4_find_type(grp->file->nc4_info, xtype, &type_info))
|
||||
return NC_EBADTYPE;
|
||||
|
||||
/* cast needed for braindead systems with signed size_t */
|
||||
|
@ -433,7 +433,8 @@ test_nc_put_var_$1(void)
|
||||
assert(var_rank[i] <= MAX_RANK);
|
||||
assert(var_nels[i] <= MAX_NELS);
|
||||
err = nc_put_var_$1(BAD_ID, i, value);
|
||||
|
||||
IF (err != NC_EBADID)
|
||||
error("bad ncid: status = %d", err);
|
||||
nels = 1;
|
||||
for (j = 0; j < var_rank[i]; j++) {
|
||||
nels *= var_shape[i][j];
|
||||
|
@ -264,10 +264,14 @@ test_nc_inq(void)
|
||||
int ngatts0;
|
||||
int recdim0;
|
||||
err = nc_enddef(ncid2); /* enter data mode */
|
||||
IF (err)
|
||||
error("nc_enddef: %s", nc_strerror(err));
|
||||
err = nc_inq(ncid2, &ndims0, &nvars0, &ngatts0, &recdim0);
|
||||
IF (err)
|
||||
error("nc_inq: %s", nc_strerror(err));
|
||||
err = nc_redef(ncid2); /* enter define mode */
|
||||
IF (err)
|
||||
error("nc_redef: %s", nc_strerror(err));
|
||||
/* Check that inquire still works in define mode */
|
||||
err = nc_inq(ncid2, &ndims, &nvars, &ngatts, &recdim);
|
||||
IF (err)
|
||||
|
@ -522,6 +522,8 @@ test_nc_def_dim(void)
|
||||
IF (dimid != 0)
|
||||
error("Unexpected recdim");
|
||||
err = nc_inq_dimlen(ncid, dimid, &length);
|
||||
IF (err)
|
||||
error("nc_inq_dimlen: %s", nc_strerror(err));
|
||||
IF (length != 0)
|
||||
error("Unexpected length");
|
||||
err = nc_def_dim(ncid, "abc", NC_UNLIMITED, &dimid);
|
||||
@ -600,6 +602,8 @@ test_nc_rename_dim(void)
|
||||
IF (err)
|
||||
error("nc_rename_dim: %s", nc_strerror(err));
|
||||
err = nc_inq_dimname(ncid, 2, name);
|
||||
IF (err)
|
||||
error("nc_inq_dimname: %s", nc_strerror(err));
|
||||
IF (strcmp(name, "abc") != 0)
|
||||
error("Unexpected name: %s", name);
|
||||
err = nc_rename_dim(ncid, 0, "abc");
|
||||
@ -2072,6 +2076,6 @@ test_nc_set_default_format(void)
|
||||
}
|
||||
|
||||
/* Remove the left-over file. */
|
||||
if ((err = remove(scratch)))
|
||||
if (remove(scratch))
|
||||
error("remove of %s failed", scratch);
|
||||
}
|
||||
|
@ -100,10 +100,13 @@ main() {/* create tst_diskless2.nc */
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
econst = 0;
|
||||
stat = nc_insert_enum(root_grp, enum_t_typ, "Clear", &econst);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
econst = 1;
|
||||
stat = nc_insert_enum(root_grp, enum_t_typ, "Cumulonimbus", &econst);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
econst = 2;
|
||||
stat = nc_insert_enum(root_grp, enum_t_typ, "Stratus", &econst);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
stat = nc_def_opaque(root_grp, 11, "opaque_t", &opaque_t_typ);
|
||||
|
@ -124,7 +124,7 @@ test_one_with_att(const char *testfile)
|
||||
if (ndims != 1 && nvars != 1 && natts != 0 && unlimdimid != 0) ERR;
|
||||
if (nc_get_var_text(ncid, varid, &data_in)) ERR;
|
||||
if (data_in != data) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in));
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in)) ERR;
|
||||
if (data_in != data) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
return 0;
|
||||
|
@ -457,7 +457,7 @@ main(int argc, char **argv)
|
||||
if (data1[nn] != data2[nn]) {
|
||||
badvars++;
|
||||
fprintf(stderr,
|
||||
"\tFrom nofill file, %s[%d] = %d\tFrom fill file, %s[%d] = %d\n",
|
||||
"\tFrom nofill file, %s[%lu] = %d\tFrom fill file, %s[%lu] = %d\n",
|
||||
varname1, nn, data1[nn], varname2, nn, data2[nn]);
|
||||
break;
|
||||
};
|
||||
|
@ -53,7 +53,7 @@ test_small_atts(const char *testfile)
|
||||
if (ndims != 0 && nvars != 0 && natts != 1 && unlimdimid != -1) ERR;
|
||||
if (nc_inq_attlen(ncid, NC_GLOBAL, ATT_NAME, &len_in)) ERR;
|
||||
if (len_in != t + 1) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, att_in));
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, att_in)) ERR;
|
||||
if (strncmp(att_in, att, t)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
}
|
||||
@ -292,7 +292,7 @@ test_one_growing_with_att(const char *testfile)
|
||||
index[0] = r;
|
||||
if (nc_get_var1_text(ncid, 0, index, &data_in)) ERR;
|
||||
if (data_in != data[r]) ERR;
|
||||
if (nc_get_att_text(ncid, varid, att_name, &data_in));
|
||||
if (nc_get_att_text(ncid, varid, att_name, &data_in)) ERR;
|
||||
if (data_in != data[r]) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
} /* Next record. */
|
||||
@ -388,7 +388,7 @@ test_one_with_att(const char *testfile)
|
||||
if (ndims != 1 && nvars != 1 && natts != 0 && unlimdimid != 0) ERR;
|
||||
if (nc_get_var_text(ncid, varid, &data_in)) ERR;
|
||||
if (data_in != data) ERR;
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in));
|
||||
if (nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in)) ERR;
|
||||
if (data_in != data) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
return 0;
|
||||
|
@ -38,7 +38,7 @@ main(int argc, char **argv)
|
||||
* NC_FILL_INT */
|
||||
if (nc_def_var(ncid, VAR3_NAME, NC_INT, VAR_RANK, 0, &var3id)) ERR;
|
||||
if (nc_def_var_endian(ncid, var3id, NC_ENDIAN_BIG)) ERR;
|
||||
if (nc_put_var(ncid, var3id, &fill));
|
||||
if (nc_put_var(ncid, var3id, &fill)) ERR;
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Check it out. */
|
||||
|
@ -418,8 +418,8 @@ test_redef(int format)
|
||||
/* This will fail, except for netcdf-4/hdf5, which permits any
|
||||
* name. */
|
||||
if (format != NC_FORMAT_NETCDF4)
|
||||
if ((ret = nc_def_dim(ncid, REDEF_NAME_ILLEGAL, REDEF_DIM2_LEN,
|
||||
&dimids[1])) != NC_EBADNAME) ERR;
|
||||
if (nc_def_dim(ncid, REDEF_NAME_ILLEGAL, REDEF_DIM2_LEN,
|
||||
&dimids[1]) != NC_EBADNAME) ERR;
|
||||
|
||||
if (nc_def_dim(ncid, REDEF_DIM1_NAME, REDEF_DIM1_LEN, &dimids[0])) ERR;
|
||||
if (nc_def_dim(ncid, REDEF_DIM2_NAME, REDEF_DIM2_LEN, &dimids[1])) ERR;
|
||||
|
@ -424,7 +424,7 @@ main(int argc, char **argv)
|
||||
if (nc_get_var(ncid, varid, data_in)) ERR;
|
||||
for (i = 0; i < DHR_LEN; i++)
|
||||
if (strcmp(data_in[i], data[i])) ERR;
|
||||
if (nc_free_string(DHR_LEN, data_in));
|
||||
if (nc_free_string(DHR_LEN, data_in)) ERR;
|
||||
|
||||
/* Check the empty var and att. */
|
||||
if (nc_inq_varid(ncid, VAR_NAME2, &varid)) ERR;
|
||||
|
@ -190,7 +190,6 @@ variables:
|
||||
:WMOStationNumber = -1 ;
|
||||
:Location = "Louisville, Colorado" ;
|
||||
:AlignmentDeg = 0.f ;
|
||||
:FrequencyHz = 4.49e+08f ;
|
||||
:LapxmVersion = "2.5.0.0" ;
|
||||
:ConfigFile = "NetCDF4 10.cfg" ;
|
||||
:DataTypes = "Moments," ;
|
||||
|
@ -42,13 +42,13 @@ chunkspec_parse(int ncid, const char *spec) {
|
||||
size_t ndims = 0;
|
||||
int idim;
|
||||
int ret;
|
||||
int comma_seen = 0;
|
||||
|
||||
chunkspecs.ndims = 0;
|
||||
if (!spec || *spec == '\0')
|
||||
return NC_NOERR;
|
||||
/* Count unescaped commas, handle consecutive unescaped commas as error */
|
||||
for(cp = spec; *cp; cp++) {
|
||||
int comma_seen = 0;
|
||||
if(*cp == ',' && *pp != '\\') {
|
||||
if(comma_seen) { /* consecutive commas detected */
|
||||
return(NC_EINVAL);
|
||||
@ -65,7 +65,6 @@ chunkspec_parse(int ncid, const char *spec) {
|
||||
chunkspecs.dimids = (int *) emalloc(ndims * sizeof(int));
|
||||
chunkspecs.chunksizes = (size_t *) emalloc(ndims * sizeof(size_t));
|
||||
/* Look up dimension ids and assign chunksizes */
|
||||
cp = spec;
|
||||
pp = spec;
|
||||
np = spec;
|
||||
idim = 0;
|
||||
|
@ -190,7 +190,6 @@ variables:
|
||||
:WMOStationNumber = -1 ;
|
||||
:Location = "Louisville, Colorado" ;
|
||||
:AlignmentDeg = 0.f ;
|
||||
:FrequencyHz = 4.49e+08f ;
|
||||
:LapxmVersion = "2.5.0.0" ;
|
||||
:ConfigFile = "NetCDF4 10.cfg" ;
|
||||
:DataTypes = "Moments," ;
|
||||
|
@ -729,6 +729,8 @@ pr_att(
|
||||
case NC_UINT64:
|
||||
value = *((uint64_t *)data + i);
|
||||
break;
|
||||
default:
|
||||
error("enum must have an integer base type: %d", base_nc_type);
|
||||
}
|
||||
NC_CHECK( nc_inq_enum_ident(ncid, att.type, value,
|
||||
enum_name));
|
||||
|
@ -81,6 +81,7 @@ lput(const char *cp) {
|
||||
* general lput-type function.
|
||||
*/
|
||||
|
||||
#define CDL_COMMENT_PREFIX "// "
|
||||
void
|
||||
lput2(
|
||||
const char *cp, /* string to print */
|
||||
@ -91,8 +92,7 @@ lput2(
|
||||
{
|
||||
static int linep; /* current line position (number of */
|
||||
/* chars); saved between calls */
|
||||
static char *prefix = "// "; /* prefix for CDL comment */
|
||||
int len_prefix = strlen (prefix);
|
||||
int len_prefix = strlen (CDL_COMMENT_PREFIX);
|
||||
boolean make_newline;
|
||||
|
||||
size_t len1 = strlen(cp); /* length of input string */
|
||||
@ -122,14 +122,14 @@ lput2(
|
||||
|
||||
if (len_prefix > 0) {
|
||||
if (first_item || make_newline) {
|
||||
printf (prefix);
|
||||
printf (CDL_COMMENT_PREFIX);
|
||||
linep = linep + len_prefix;
|
||||
}
|
||||
}
|
||||
|
||||
/* (3) Output caller's string value. */
|
||||
|
||||
printf (cp);
|
||||
printf ("%s", cp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,6 +52,7 @@ nc_get_iter(Symbol* vsym,
|
||||
stat = nciter_ndims(vsym, &ndims);
|
||||
CHECK(stat, nciter_ndims);
|
||||
stat = nciter_dimlens(vsym,dimsizes);
|
||||
CHECK(stat, nciter_dimlens);
|
||||
/* compute total # elements */
|
||||
nvalues=1;
|
||||
for(dim = 0; dim < ndims; dim++) {
|
||||
|
@ -64,7 +64,7 @@ test_nccreate(path)
|
||||
nerrs++;
|
||||
}
|
||||
/* this call should fail, since we're using NC_NOCLOBBER mode */
|
||||
if ((ncid = nccreate(path, NC_NOCLOBBER)) != -1) {
|
||||
if (nccreate(path, NC_NOCLOBBER) != -1) {
|
||||
error("%s: nccreate failed to honor NC_NOCLOBBER mode", pname);
|
||||
nerrs++;
|
||||
}
|
||||
@ -114,7 +114,7 @@ test_ncopen(path)
|
||||
(void) fprintf(stderr, "*** Testing %s ...\t\t", &pname[5]);
|
||||
|
||||
/* Open a nonexistent file */
|
||||
if((ncid0 = ncopen(xpath, NC_NOWRITE)) != -1) {
|
||||
if(ncopen(xpath, NC_NOWRITE) != -1) {
|
||||
error("%s: ncopen should fail opening nonexistent file",
|
||||
pname);
|
||||
return ++nerrs;
|
||||
@ -148,7 +148,7 @@ test_ncopen(path)
|
||||
return ++nerrs;
|
||||
}
|
||||
|
||||
if((ncid0 = ncopen(TEMP_FILE_NAME, NC_NOWRITE)) != -1) {
|
||||
if(ncopen(TEMP_FILE_NAME, NC_NOWRITE) != -1) {
|
||||
error("%s: ncopen should fail opening non-netCDF file",
|
||||
pname);
|
||||
return ++nerrs;
|
||||
|
@ -175,7 +175,6 @@ create_file()
|
||||
size_t aa_startset[1] = {0} ;
|
||||
size_t aa_countset[1] = {4} ;
|
||||
stat = nc_put_vara(ncid, aa_id, aa_startset, aa_countset, aa_data);
|
||||
stat = nc_put_vara(ncid, aa_id, aa_startset, aa_countset, aa_data);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
@ -184,7 +183,6 @@ create_file()
|
||||
size_t bb_startset[2] = {0, 0} ;
|
||||
size_t bb_countset[2] = {3, 3} ;
|
||||
stat = nc_put_vara(ncid, bb_id, bb_startset, bb_countset, bb_data);
|
||||
stat = nc_put_vara(ncid, bb_id, bb_startset, bb_countset, bb_data);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
@ -193,7 +191,6 @@ create_file()
|
||||
size_t dd_startset[1] = {0} ;
|
||||
size_t dd_countset[1] = {3} ;
|
||||
stat = nc_put_vara(ncid, dd_id, dd_startset, dd_countset, dd_data);
|
||||
stat = nc_put_vara(ncid, dd_id, dd_startset, dd_countset, dd_data);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,6 @@ test_ncvardef(path)
|
||||
ncclose(cdfid); return ++nerrs;
|
||||
}
|
||||
/* try bad ids in dims vector, should fail */
|
||||
id = va[0].dims[0];
|
||||
va[0].dims[va[0].ndims-1] = -1;
|
||||
if (ncvardef(cdfid, "baddims", va[0].type, va[0].ndims, va[0].dims)
|
||||
!= -1) {
|
||||
|
Loading…
Reference in New Issue
Block a user