Skip to content

Commit a0b2f27

Browse files
Fix int/hsize_t and snprintf compiler issues
Fix compiler issues
2 parents 3ffa6b4 + e554a4e commit a0b2f27

File tree

5 files changed

+39
-48
lines changed

5 files changed

+39
-48
lines changed

ghpages/releases/releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For details, see the [BSD_LICENSE_README](https://raw.githubusercontent.com/LLNL
1212

1313
Date | Version | Sources | Documentation
1414
:--- | ---: | :--- | ---
15-
Nov 2025 | 4.12.0 | [Legacy+BSD][4120] | [Release notes][badlink] / [User Manual][4120um]
15+
Nov 2025 | 4.12.0 | [Legacy+BSD][4120] | [Release notes][4120] / [User Manual][4120um]
1616
Sep 2023 | 4.11.1 | [Legacy][4111] / [BSD][4111b] | [Release notes][4111rn] / [User Manual][4111um]
1717
Sep 2022 | 4.11 | [Legacy][411] / [BSD][411b] | [Release notes][411rn]
1818
Feb 2016 | 4.10.2 | [Legacy][4102] / [BSD][4102b] | [See 4.10.1 Release notes][4102rn]

src/hdf5_drv/silo_hdf5.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,20 +1889,18 @@ db_hdf5_get_obj_dsnames(DBfile *_dbfile, char const *name, int *dscount, char **
18891889
*/
18901890
PRIVATE hid_t
18911891
db_hdf5_get_cmemb(hid_t compound_type, int membno, int *ndims/*out*/,
1892-
int size[3]/*out*/)
1892+
hsize_t size[3]/*out*/)
18931893
{
18941894
hid_t type;
18951895

18961896
if ((type=H5Tget_member_type(compound_type, membno))<0) return -1;
18971897

18981898
#if (H5_VERS_MAJOR==1 && H5_VERS_MINOR>=4) || H5_VERS_MAJOR>1
18991899
if (H5T_ARRAY==H5Tget_class(type)) {
1900-
hsize_t bigdims[3];
19011900
int i;
19021901
*ndims = H5Tget_array_ndims(type);
19031902
assert(*ndims<=3);
1904-
H5Tget_array_dims(type, bigdims);
1905-
for (i=0; i<*ndims; i++) size[i] = bigdims[i];
1903+
H5Tget_array_dims(type, size);
19061904
type = H5Tget_super(type);
19071905
} else {
19081906
*ndims = 0;
@@ -1931,16 +1929,14 @@ db_hdf5_get_cmemb(hid_t compound_type, int membno, int *ndims/*out*/,
19311929
*/
19321930
PRIVATE int
19331931
db_hdf5_put_cmemb(hid_t compound_type, char const *name, size_t offset,
1934-
int ndims, int const *dim, hid_t type)
1932+
int ndims, hsize_t const *dim, hid_t type)
19351933
{
19361934
int retval;
19371935

19381936
#if (H5_VERS_MAJOR==1 && H5_VERS_MINOR>=4) || H5_VERS_MAJOR>1
19391937
if (ndims) {
1940-
hsize_t bigdims[16];
19411938
int i;
1942-
for (i=0; i<ndims; i++) bigdims[i] = dim[i];
1943-
type = H5Tarray_create(type, ndims, bigdims);
1939+
type = H5Tarray_create(type, ndims, dim);
19441940
}
19451941
retval = H5Tinsert(compound_type, name, offset, type);
19461942
if (ndims) H5Tclose(type);
@@ -3805,10 +3801,11 @@ db_hdf5_get_comp_var(DBfile *_dbfile, char const *name, hsize_t *nelmts,
38053801
break;
38063802
case H5T_ARRAY:
38073803
{
3808-
int i, ndims, size[3], len = 1;
3804+
int i, ndims, len = 1;
3805+
hsize_t size[3];
38093806
comptype = db_hdf5_get_cmemb(stypeid, membno, &ndims, size);
38103807
for (i = 0; i < ndims; i++)
3811-
len *= size[i];
3808+
len *= (int) size[i];
38123809
numvals = len;
38133810
break;
38143811
}
@@ -6616,7 +6613,8 @@ copy_obj(hid_t hobj, char const *name, void *op_data)
66166613
s1024 = H5Tcopy(H5T_C_S1);
66176614
H5Tset_size(s1024, 1024);
66186615
for (i=0; i<nmembs; i++) {
6619-
int ndims, j, memb_size[4];
6616+
int ndims, j;
6617+
hsize_t memb_size[4];
66206618
hid_t member_type = db_hdf5_get_cmemb(atype, i, &ndims, memb_size);
66216619

66226620
if (H5Tget_class(member_type) == H5T_STRING)
@@ -7075,7 +7073,8 @@ db_hdf5_GetComponentStuff(DBfile *_dbfile, char const *objname, char const *comp
70757073
DBfile_hdf5 *dbfile = (DBfile_hdf5*)_dbfile;
70767074
static char *me = "db_hdf5_GetComponent";
70777075
hid_t o=-1, attr=-1, atype=-1, ftype=-1, mtype=-1, dset=-1;
7078-
int datatype, mno, n, ndims, i, dim[3], mult, complen, mnof=-1, mnofidx=-1;
7076+
int datatype, mno, n, ndims, i, mult, complen, mnof=-1, mnofidx=-1;
7077+
hsize_t dim[3];
70797078
char *mnofname=0;
70807079
void *retval=NULL;
70817080

@@ -7185,7 +7184,7 @@ db_hdf5_GetComponentStuff(DBfile *_dbfile, char const *objname, char const *comp
71857184
UNWIND();
71867185
}
71877186

7188-
for (i=0, mult=1; i<ndims; i++) mult *= dim[i];
7187+
for (i=0, mult=1; i<ndims; i++) mult *= (int) dim[i];
71897188

71907189
if (just_get_datatype == 0)
71917190
{
@@ -8821,7 +8820,8 @@ db_hdf5_GetObject(DBfile *_dbfile, char const *name)
88218820
hid_t o=-1, attr=-1, atype=-1, h5str=-1;
88228821
char *file_value=NULL, *mem_value=NULL, *bkg=NULL, bigname[1024];
88238822
DBObjectType objtype;
8824-
int _objtype, nmembs, i, j, memb_size[4];
8823+
int _objtype, nmembs, i, j;
8824+
hsize_t memb_size[4];
88258825
DBobject *obj=NULL;
88268826
size_t asize, nelmts, msize;
88278827

src/taurus/silo_taurus.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,10 @@ db_taur_NewToc(DBfile *_dbfile)
484484
toc->dir_names[i] = ALLOC_N(char, 12);
485485

486486
if (taurus->nstates < 100) {
487-
snprintf(toc->dir_names[i], 12, "state%02d", i);
487+
snprintf(toc->dir_names[i], 12, "state%02d", i%100);
488488
}
489489
else {
490-
snprintf(toc->dir_names[i], 12, "state%03d", i);
490+
snprintf(toc->dir_names[i], 12, "state%03d", i%1000);
491491
}
492492
}
493493
toc->ndir = taurus->nstates;
@@ -1455,9 +1455,9 @@ db_taur_InqMeshname(DBfile *_dbfile, char const *var_name, char *mesh_name)
14551455
*/
14561456
if (strcmp(var_name, "mat1") == 0) {
14571457
if (taurus->nstates < 100)
1458-
snprintf(mesh_name, 14, "/state%02d/mesh1", taurus->state);
1458+
snprintf(mesh_name, 16, "/state%02d/mesh1", taurus->state%100);
14591459
else
1460-
snprintf(mesh_name, 15, "/state%03d/mesh1", taurus->state);
1460+
snprintf(mesh_name, 17, "/state%03d/mesh1", taurus->state%1000);
14611461
return (0);
14621462
}
14631463
}
@@ -1776,7 +1776,7 @@ db_taur_cd(TAURUSfile *taurus, char const *path)
17761776
int state;
17771777
char *dir;
17781778
char opath[160];
1779-
char npath[160];
1779+
char npath[256];
17801780

17811781
/*
17821782
* Form the new path.
@@ -1786,7 +1786,7 @@ db_taur_cd(TAURUSfile *taurus, char const *path)
17861786
}
17871787
else {
17881788
db_taur_pwd(taurus, opath);
1789-
snprintf(npath, 256, "%s/%s", opath, path);
1789+
snprintf(npath, 256, "%.160s/%.95s", opath, path);
17901790
}
17911791
reduce_path(npath);
17921792

@@ -1873,19 +1873,19 @@ db_taur_pwd(TAURUSfile *taurus, char *path)
18731873
else {
18741874
if (taurus->idir == -1) {
18751875
if (taurus->nstates < 100) {
1876-
snprintf(path, 7, "/state%02d", taurus->state);
1876+
snprintf(path, 10, "/state%02d", taurus->state%100);
18771877
}
18781878
else {
1879-
snprintf(path, 8, "/state%03d", taurus->state);
1879+
snprintf(path, 11, "/state%03d", taurus->state%1000);
18801880
}
18811881
}
18821882
else {
18831883
if (taurus->nstates < 100) {
1884-
snprintf(path, 256, "/state%02d/%s", taurus->state,
1884+
snprintf(path, 256, "/state%02d/%.245s", taurus->state%100,
18851885
dir_names[taurus->idir]);
18861886
}
18871887
else {
1888-
snprintf(path, 256, "/state%03d/%s", taurus->state,
1888+
snprintf(path, 256, "/state%03d/%.244s", taurus->state%1000,
18891889
dir_names[taurus->idir]);
18901890
}
18911891
}

tests/test_mat_compression.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ main(int argc, char *argv[])
249249
int nchars;
250250
vfrac_varnames[i] = (char *) malloc(256*sizeof(char));
251251
if (mat->matnames && mat->matnames[i])
252-
nchars = snprintf(vfrac_varnames[i], 256, "%s_%s_%d_vfracs", omat, mat->matnames[i], mat->matnos[i]);
252+
nchars = snprintf(vfrac_varnames[i], 256, "%.163s_%.64s_%d_vfracs", omat, mat->matnames[i], mat->matnos[i]);
253253
else
254-
nchars = snprintf(vfrac_varnames[i], 256, "%s_%d_vfracs", omat, mat->matnos[i]);
254+
nchars = snprintf(vfrac_varnames[i], 256, "%.227s_%0d_vfracs", omat, mat->matnos[i]);
255255
assert(nchars > 0 && nchars < 256);
256256
DBWrite(outfile, vfrac_varnames[i], vfracs[i], mat->dims, mat->ndims, mat->datatype);
257257
total_file_bytes += DBGetVarByteLengthInFile(outfile, vfrac_varnames[i]);

tests/testall.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ be used for advertising or product endorsement purposes.
7474
*
7575
*/
7676

77+
#include <assert.h>
7778
#include <sys/types.h>
7879
#include <sys/stat.h>
7980
#include <fcntl.h>
@@ -1415,6 +1416,7 @@ build_rect3d(DBfile * dbfile, int size, int order)
14151416
double dist;
14161417

14171418
int binf;
1419+
ssize_t wrsz;
14181420

14191421
switch (size) {
14201422
case 1:
@@ -1645,11 +1647,13 @@ build_rect3d(DBfile * dbfile, int size, int order)
16451647

16461648
DBPutQuadvar1(dbfile, var1name, meshname, d, zdims, ndims, NULL, 0,
16471649
DB_FLOAT, DB_ZONECENT, optlist);
1648-
write(binf, d, zdims[0]*zdims[1]*zdims[2]*sizeof(float));
1650+
wrsz = write(binf, d, zdims[0]*zdims[1]*zdims[2]*sizeof(float));
1651+
assert(wrsz==zdims[0]*zdims[1]*zdims[2]*sizeof(float));
16491652

16501653
DBPutQuadvar1(dbfile, var2name, meshname, p, zdims, ndims, NULL, 0,
16511654
DB_FLOAT, DB_ZONECENT, optlist);
1652-
write(binf, p, zdims[0]*zdims[1]*zdims[2]*sizeof(float));
1655+
wrsz = write(binf, p, zdims[0]*zdims[1]*zdims[2]*sizeof(float));
1656+
assert(wrsz==zdims[0]*zdims[1]*zdims[2]*sizeof(float));
16531657
close(binf);
16541658
printf("zsize = nz=%d, ny=%d, nx=%d\n", zdims[2], zdims[1], zdims[0]);
16551659

@@ -1661,31 +1665,18 @@ build_rect3d(DBfile * dbfile, int size, int order)
16611665

16621666
DBPutQuadvar1(dbfile, var3name, meshname, u, dims, ndims, NULL, 0,
16631667
DB_FLOAT, DB_NODECENT, optlist);
1664-
write(binf, u, dims[0]*dims[1]*dims[2]*sizeof(float));
1668+
wrsz = write(binf, u, dims[0]*dims[1]*dims[2]*sizeof(float));
1669+
assert(wrsz==dims[0]*dims[1]*dims[2]*sizeof(float));
16651670

16661671
DBPutQuadvar1(dbfile, var4name, meshname, v, dims, ndims, NULL, 0,
16671672
DB_FLOAT, DB_NODECENT, optlist);
1668-
/*write(binf, v, dims[0]*dims[1]*dims[2]*sizeof(float));*/
1673+
wrsz = write(binf, v, dims[0]*dims[1]*dims[2]*sizeof(float));
1674+
assert(wrsz==dims[0]*dims[1]*dims[2]*sizeof(float));
16691675

16701676
DBPutQuadvar1(dbfile, var5name, meshname, w, dims, ndims, NULL, 0,
16711677
DB_FLOAT, DB_NODECENT, optlist);
1672-
/*write(binf, w, dims[0]*dims[1]*dims[2]*sizeof(float));*/
1673-
#if 0
1674-
{ int i, j, k;
1675-
for (k = 0; k < dims[2]; k++)
1676-
{
1677-
for (j = 0; j < dims[1]; j++)
1678-
{
1679-
for (i = 0; i < dims[0]; i++)
1680-
{
1681-
write(binf, &u[k*dims[1]*dims[0]+j*dims[0]+i], sizeof(float));
1682-
write(binf, &v[k*dims[1]*dims[0]+j*dims[0]+i], sizeof(float));
1683-
write(binf, &w[k*dims[1]*dims[0]+j*dims[0]+i], sizeof(float));
1684-
}
1685-
}
1686-
}
1687-
}
1688-
#endif
1678+
wrsz = write(binf, w, dims[0]*dims[1]*dims[2]*sizeof(float));
1679+
assert(wrsz==dims[0]*dims[1]*dims[2]*sizeof(float));
16891680
close(binf);
16901681
printf("size = nz=%d, ny=%d, nx=%d\n", dims[2], dims[1], dims[0]);
16911682

0 commit comments

Comments
 (0)