summaryrefslogtreecommitdiffstats
path: root/src/H5O.c
diff options
context:
space:
mode:
authorRobb Matzke <matzke@llnl.gov>1998-06-23 03:41:22 (GMT)
committerRobb Matzke <matzke@llnl.gov>1998-06-23 03:41:22 (GMT)
commit4bf629adc96541fda24bafbdde00fd4ff92be344 (patch)
tree8e6d57995ba50bafdf172df9d480bd99cdb1230e /src/H5O.c
parent62607debf74800472572e65517ed284aef19a63c (diff)
downloadhdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.zip
hdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.tar.gz
hdf5-4bf629adc96541fda24bafbdde00fd4ff92be344.tar.bz2
[svn-r435] ./INSTALL
./INSTALL_MAINT ./README ./RELEASE Partially updated for second alpha, but haven't updated version numbers yet. ./src/H5.c ./src/H5A.c ./src/H5AC.c ./src/H5B.c ./src/H5D.c ./src/H5F.c ./src/H5Fcore.c ./src/H5Ffamily.c ./src/H5Fistore.c ./src/H5Fmpio.c ./src/H5Fsec2.c ./src/H5Fsplit.c ./src/H5Fstdio.c ./src/H5G.c ./src/H5Gnode.c ./src/H5HG.c ./src/H5HL.c ./src/H5I.c ./src/H5MM.c ./src/H5MMprivate.h ./src/H5O.c ./src/H5Oattr.c ./src/H5Ocomp.c ./src/H5Ocont.c ./src/H5Odtype.c ./src/H5Oefl.c ./src/H5Olayout.c ./src/H5Oname.c ./src/H5Osdspace.c ./src/H5Oshared.c ./src/H5Ostab.c ./src/H5P.c ./src/H5S.c ./src/H5T.c ./src/H5Tconv.c ./src/H5detect.c ./test/hyperslab.c ./test/istore.c Changed memory allocation functions so they fail instead of dumping core. The `x' was removed from the name to remind us of that: H5MM_xmalloc() -> H5MM_malloc(), etc. H5MM_calloc() takes one argument like H5MM_malloc() instead of two like calloc() because we almost always called it with `1' for one of the arguments anyway. The only difference between the two functions is that H5MM_calloc() returns memory which is initialized to zero. ./src/H5Gent.c ./src/H5Gprivate.h Removed H5G_ent_calloc() since it wasn't used. ./src/H5Fistore.c Fixed a bug found by Albert. Thanks, Albert! This fix combined with the changes to memory allocation prevent the library from failing an assertion if the application uses an unreasonable size for chunks (like Alberts 10000x10000x4). ./src/H5MF.c ./src/H5MFprivate.h Changed H5MF_free() to H5MF_xfree() since calling it with an undefined address is allowed.
Diffstat (limited to 'src/H5O.c')
-rw-r--r--src/H5O.c145
1 files changed, 106 insertions, 39 deletions
diff --git a/src/H5O.c b/src/H5O.c
index d4c861e..29eb583 100644
--- a/src/H5O.c
+++ b/src/H5O.c
@@ -151,11 +151,14 @@ H5O_create(H5F_t *f, size_t size_hint, H5G_entry_t *ent/*out*/)
ent->file = f;
if (H5MF_alloc(f, H5MF_META, (hsize_t)size, &(ent->header)/*out*/) < 0) {
HRETURN_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL,
- "unable to allocate file space for object header hdr");
+ "file allocation failed for object header header");
}
/* allocate the object header and fill in header fields */
- oh = H5MM_xcalloc(1, sizeof(H5O_t));
+ if (NULL==(oh = H5MM_calloc(sizeof(H5O_t)))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
oh->dirty = TRUE;
oh->version = H5O_VERSION;
oh->nlink = 0;
@@ -163,20 +166,27 @@ H5O_create(H5F_t *f, size_t size_hint, H5G_entry_t *ent/*out*/)
/* create the chunk list and initialize the first chunk */
oh->nchunks = 1;
oh->alloc_nchunks = H5O_NCHUNKS;
- oh->chunk = H5MM_xmalloc(oh->alloc_nchunks * sizeof(H5O_chunk_t));
-
+ if (NULL==(oh->chunk=H5MM_malloc(oh->alloc_nchunks*sizeof(H5O_chunk_t)))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
tmp_addr = ent->header;
H5F_addr_inc(&tmp_addr, (hsize_t)H5O_SIZEOF_HDR(f));
oh->chunk[0].dirty = TRUE;
oh->chunk[0].addr = tmp_addr;
oh->chunk[0].size = size_hint;
- oh->chunk[0].image = H5MM_xcalloc(1, size_hint);
-
+ if (NULL==(oh->chunk[0].image = H5MM_calloc(size_hint))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+
/* create the message list and initialize the first message */
oh->nmesgs = 1;
oh->alloc_nmesgs = H5O_NMESGS;
- oh->mesg = H5MM_xcalloc(oh->alloc_nmesgs, sizeof(H5O_mesg_t));
-
+ if (NULL==(oh->mesg=H5MM_calloc(oh->alloc_nmesgs*sizeof(H5O_mesg_t)))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
oh->mesg[0].type = H5O_NULL;
oh->mesg[0].dirty = TRUE;
oh->mesg[0].native = NULL;
@@ -331,7 +341,10 @@ H5O_load(H5F_t *f, const haddr_t *addr, const void __unused__ *_udata1,
assert(!_udata2);
/* allocate ohdr and init chunk list */
- oh = H5MM_xcalloc(1, sizeof(H5O_t));
+ if (NULL==(oh = H5MM_calloc(sizeof(H5O_t)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
/* read fixed-lenth part of object header */
hdr_size = H5O_SIZEOF_HDR(f);
@@ -364,16 +377,24 @@ H5O_load(H5F_t *f, const haddr_t *addr, const void __unused__ *_udata1,
/* build the message array */
oh->alloc_nmesgs = MAX(H5O_NMESGS, nmesgs);
- oh->mesg = H5MM_xcalloc(oh->alloc_nmesgs, sizeof(H5O_mesg_t));
+ if (NULL==(oh->mesg=H5MM_calloc(oh->alloc_nmesgs*sizeof(H5O_mesg_t)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
/* read each chunk from disk */
while (H5F_addr_defined(&chunk_addr)) {
/* increase chunk array size */
if (oh->nchunks >= oh->alloc_nchunks) {
- oh->alloc_nchunks += H5O_NCHUNKS;
- oh->chunk = H5MM_xrealloc(oh->chunk,
- oh->alloc_nchunks * sizeof(H5O_chunk_t));
+ size_t na = oh->alloc_nchunks + H5O_NCHUNKS;
+ H5O_chunk_t *x = H5MM_realloc (oh->chunk, na*sizeof(H5O_chunk_t));
+ if (!x) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
+ oh->alloc_nchunks = na;
+ oh->chunk = x;
}
/* read the chunk raw data */
@@ -381,7 +402,10 @@ H5O_load(H5F_t *f, const haddr_t *addr, const void __unused__ *_udata1,
oh->chunk[chunkno].dirty = FALSE;
oh->chunk[chunkno].addr = chunk_addr;
oh->chunk[chunkno].size = chunk_size;
- oh->chunk[chunkno].image = H5MM_xmalloc(chunk_size);
+ if (NULL==(oh->chunk[chunkno].image = H5MM_malloc(chunk_size))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL,
+ "memory allocation failed");
+ }
if (H5F_block_read(f, &chunk_addr, (hsize_t)chunk_size, H5D_XFER_DFLT,
oh->chunk[chunkno].image) < 0) {
HGOTO_ERROR(H5E_OHDR, H5E_READERROR, NULL,
@@ -1140,7 +1164,10 @@ H5O_modify(H5G_entry_t *ent, const H5O_class_t *type, intn overwrite,
HGOTO_ERROR (H5E_OHDR, H5E_UNSUPPORTED, FAIL,
"message class is not sharable");
}
- sh_mesg = H5MM_xcalloc (1, sizeof *sh_mesg);
+ if (NULL==(sh_mesg = H5MM_calloc (sizeof *sh_mesg))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
if ((type->get_share)(ent->file, mesg, sh_mesg/*out*/)<0) {
/*
* If the message isn't shared then turn off the shared bit
@@ -1396,9 +1423,13 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
old_addr = oh->chunk[chunkno].image;
/* Be careful not to indroduce garbage */
- oh->chunk[chunkno].image = H5MM_xrealloc(old_addr,
- (oh->chunk[chunkno].size +
- delta));
+ oh->chunk[chunkno].image = H5MM_realloc(old_addr,
+ (oh->chunk[chunkno].size +
+ delta));
+ if (NULL==oh->chunk[chunkno].image) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
HDmemset(oh->chunk[chunkno].image + oh->chunk[chunkno].size,
0, delta);
oh->chunk[chunkno].size += delta;
@@ -1418,9 +1449,14 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
/* create a new null message */
if (oh->nmesgs >= oh->alloc_nmesgs) {
- oh->alloc_nmesgs += H5O_NMESGS;
- oh->mesg = H5MM_xrealloc(oh->mesg,
- oh->alloc_nmesgs * sizeof(H5O_mesg_t));
+ size_t na = oh->alloc_nmesgs + H5O_NMESGS;
+ H5O_mesg_t *x = H5MM_realloc (oh->mesg, na*sizeof(H5O_mesg_t));
+ if (NULL==x) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ oh->alloc_nmesgs = na;
+ oh->mesg = x;
}
delta = MAX(H5O_MIN_SIZE, size+H5O_SIZEOF_MSGHDR(f));
delta = H5O_ALIGN(delta);
@@ -1436,9 +1472,13 @@ H5O_alloc_extend_chunk(H5O_t *oh, intn chunkno, size_t size)
old_addr = oh->chunk[chunkno].image;
oh->chunk[chunkno].size += delta;
- oh->chunk[chunkno].image = H5MM_xrealloc(old_addr,
- oh->chunk[chunkno].size);
-
+ oh->chunk[chunkno].image = H5MM_realloc(old_addr,
+ oh->chunk[chunkno].size);
+ if (NULL==oh->chunk[chunkno].image) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+
/* adjust raw addresses for messages of this chunk */
if (old_addr != oh->chunk[chunkno].image) {
for (i = 0; i < oh->nmesgs; i++) {
@@ -1543,26 +1583,39 @@ H5O_alloc_new_chunk(H5F_t *f, H5O_t *oh, size_t size)
* Create the new chunk without giving it a file address.
*/
if (oh->nchunks >= oh->alloc_nchunks) {
- oh->alloc_nchunks += H5O_NCHUNKS;
- oh->chunk = H5MM_xrealloc(oh->chunk,
- oh->alloc_nchunks * sizeof(H5O_chunk_t));
+ size_t na = oh->alloc_nchunks + H5O_NCHUNKS;
+ H5O_chunk_t *x = H5MM_realloc (oh->chunk, na*sizeof(H5O_chunk_t));
+ if (!x) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ oh->alloc_nchunks = na;
+ oh->chunk = x;
}
chunkno = oh->nchunks++;
oh->chunk[chunkno].dirty = TRUE;
H5F_addr_undef(&(oh->chunk[chunkno].addr));
oh->chunk[chunkno].size = size;
- oh->chunk[chunkno].image = p = H5MM_xcalloc(1, size);
-
+ if (NULL==(oh->chunk[chunkno].image = p = H5MM_calloc(size))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+
/*
* Make sure we have enough space for all possible new messages
* that could be generated below.
*/
if (oh->nmesgs + 3 > oh->alloc_nmesgs) {
int old_alloc=oh->alloc_nmesgs;
+ size_t na = oh->alloc_nmesgs + MAX (H5O_NMESGS, 3);
+ H5O_mesg_t *x = H5MM_realloc (oh->mesg, na*sizeof(H5O_mesg_t));
+ if (!x) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ oh->alloc_nmesgs = na;
+ oh->mesg = x;
- oh->alloc_nmesgs += MAX(H5O_NMESGS, 3);
- oh->mesg = H5MM_xrealloc(oh->mesg,
- oh->alloc_nmesgs * sizeof(H5O_mesg_t));
/* Set new object header info to zeros */
HDmemset(&oh->mesg[old_alloc], 0,
(oh->alloc_nmesgs-old_alloc)*sizeof(H5O_mesg_t));
@@ -1620,7 +1673,10 @@ H5O_alloc_new_chunk(H5F_t *f, H5O_t *oh, size_t size)
*/
oh->mesg[found_null].type = H5O_CONT;
oh->mesg[found_null].dirty = TRUE;
- cont = H5MM_xcalloc(1, sizeof(H5O_cont_t));
+ if (NULL==(cont = H5MM_calloc(sizeof(H5O_cont_t)))) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
H5F_addr_undef(&(cont->addr));
cont->size = 0;
cont->chunkno = chunkno;
@@ -1707,11 +1763,16 @@ H5O_alloc(H5F_t *f, H5O_t *oh, const H5O_class_t *type, size_t size)
assert(oh->mesg[idx].raw_size - size >= H5O_SIZEOF_MSGHDR(f));
if (oh->nmesgs >= oh->alloc_nmesgs) {
- int old_alloc=oh->alloc_nmesgs;
+ int old_alloc=oh->alloc_nmesgs;
+ size_t na = oh->alloc_nmesgs + H5O_NMESGS;
+ H5O_mesg_t *x = H5MM_realloc (oh->mesg, na*sizeof(H5O_mesg_t));
+ if (!x) {
+ HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
+ oh->alloc_nmesgs = na;
+ oh->mesg = x;
- oh->alloc_nmesgs += H5O_NMESGS;
- oh->mesg = H5MM_xrealloc(oh->mesg,
- oh->alloc_nmesgs * sizeof(H5O_mesg_t));
/* Set new object header info to zeros */
HDmemset(&oh->mesg[old_alloc],0,
(oh->alloc_nmesgs-old_alloc)*sizeof(H5O_mesg_t));
@@ -1773,7 +1834,10 @@ H5O_share (H5F_t *f, const H5O_class_t *type, const void *mesg,
/* Encode the message put it in the global heap */
if ((size = (type->raw_size)(f, mesg))>0) {
- buf = H5MM_xmalloc (size);
+ if (NULL==(buf = H5MM_malloc (size))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
if ((type->encode)(f, buf, mesg)<0) {
HGOTO_ERROR (H5E_OHDR, H5E_CANTENCODE, FAIL,
"unable to encode message");
@@ -1879,7 +1943,10 @@ H5O_debug(H5F_t *f, const haddr_t *addr, FILE * stream, intn indent,
}
/* debug each message */
- sequence = H5MM_xcalloc(NELMTS(message_type_g), sizeof(int));
+ if (NULL==(sequence = H5MM_calloc(NELMTS(message_type_g)*sizeof(int)))) {
+ HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL,
+ "memory allocation failed");
+ }
for (i=0, mesg_total=0; i<oh->nmesgs; i++) {
mesg_total += H5O_SIZEOF_MSGHDR(f) + oh->mesg[i].raw_size;
fprintf(stream, "%*sMessage %d...\n", indent, "", i);