diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-08-25 20:05:42 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-08-25 20:05:42 (GMT) |
commit | b987255ed0b7c3eca9c03676f5b130f4cf080a89 (patch) | |
tree | 628d41069d1623a99ba2ec444bcbf9a60864c35e | |
parent | 90838ac388d79ef880a14878853c9c3750873984 (diff) | |
download | hdf5-b987255ed0b7c3eca9c03676f5b130f4cf080a89.zip hdf5-b987255ed0b7c3eca9c03676f5b130f4cf080a89.tar.gz hdf5-b987255ed0b7c3eca9c03676f5b130f4cf080a89.tar.bz2 |
[svn-r7404] Purpose:
Bug fix
Description:
Correct problem with mis-aligned string pointers on certain architectures
(i.e. on modi4) causing a core dump. The string pointers can be mis-aligned
due to being part of a compound datatype and how our compound type conversion
routines work.
Solution:
Allocate string with temporary variable and memcpy() the pointer to the
new string into the type conversion buffer, instead of dereferencing the type
conversion buffer directly.
Platforms tested:
FreeBSD 4.8 (sleipnir)
h5committest
-rw-r--r-- | src/H5Tvlen.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index ff9cfac..e3f367e 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -487,10 +487,11 @@ H5T_vlen_str_mem_write(H5F_t UNUSED *f, hid_t dxpl_id, void *vl_addr, void *buf, { H5MM_allocate_t alloc_func; /* Vlen allocation function */ void *alloc_info; /* Vlen allocation information */ - char **s=(char **)vl_addr; /* Pointer to the user's hvl_t information */ - size_t len; - H5P_genplist_t *plist; /* Property list */ - herr_t ret_value=SUCCEED; /* Return value */ + char **s=(char **)vl_addr; /* Pointer to the user's hvl_t information */ + char *t; /* Pointer to temporary buffer allocated */ + size_t len; /* Maximum length of the string to copy */ + H5P_genplist_t *plist; /* Property list */ + herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5T_vlen_str_mem_write, FAIL); @@ -509,17 +510,20 @@ H5T_vlen_str_mem_write(H5F_t UNUSED *f, hid_t dxpl_id, void *vl_addr, void *buf, HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value"); if(alloc_func!=NULL) { - if(NULL==(*s=(alloc_func)((size_t)((seq_len+1)*base_size),alloc_info))) + if(NULL==(t=(alloc_func)((size_t)((seq_len+1)*base_size),alloc_info))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data"); } /* end if */ else { /* Default to system malloc */ - if(NULL==(*s=H5MM_malloc((size_t)((seq_len+1)*base_size)))) + if(NULL==(t=H5MM_malloc((size_t)((seq_len+1)*base_size)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for VL data"); } /* end else */ H5_ASSIGN_OVERFLOW(len,(seq_len*base_size),hsize_t,size_t); - HDmemcpy(*s,buf,len); - (*s)[len]='\0'; + HDmemcpy(t,buf,len); + t[len]='\0'; + + /* Set pointer in user's buffer with memcpy, to avoid alignment issues */ + HDmemcpy(s,&t,sizeof(char *)); done: FUNC_LEAVE_NOAPI(ret_value); |