diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2011-09-30 15:51:15 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2011-09-30 15:51:15 (GMT) |
commit | b7f8909a58f7a20258d0b0aed76b9bec7399a411 (patch) | |
tree | 0c33f038a43e231f8daf745698d598bb5f1c5b97 /hl/test/test_lite.c | |
parent | bae6ab52199bd21d5e7f464ae308dae8646b2298 (diff) | |
download | hdf5-b7f8909a58f7a20258d0b0aed76b9bec7399a411.zip hdf5-b7f8909a58f7a20258d0b0aed76b9bec7399a411.tar.gz hdf5-b7f8909a58f7a20258d0b0aed76b9bec7399a411.tar.bz2 |
[svn-r21436] Issue 7701 - H5LTdtype_to_text had memory corruption while being querried about the size of the buffer needed. The problem happened when the internal buffer is reallocated, the new address got lost. I revised the code to pass the new address as the return value of functions. I also added two new test cases.
Tested on jam, linew, and koala.
Diffstat (limited to 'hl/test/test_lite.c')
-rw-r--r-- | hl/test/test_lite.c | 120 |
1 files changed, 114 insertions, 6 deletions
diff --git a/hl/test/test_lite.c b/hl/test/test_lite.c index 2b36eb6..c7232e2a 100644 --- a/hl/test/test_lite.c +++ b/hl/test/test_lite.c @@ -1373,16 +1373,16 @@ static int test_variables(void) if(H5Tis_variable_str(dtype)) goto out; - + if(H5Tclose(dtype)<0) goto out; - + if((dtype = H5LTtext_to_dtype("H5T_VLEN { H5T_VLEN { H5T_STD_I32BE } }", H5LT_DDL))<0) goto out; - + if(H5Tis_variable_str(dtype)) goto out; - + if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0) goto out; dt_str = (char*)calloc(str_len, sizeof(char)); @@ -1393,10 +1393,10 @@ static int test_variables(void) goto out; } free(dt_str); - + if(H5Tclose(dtype)<0) goto out; - + PASSED(); return 0; @@ -1527,6 +1527,111 @@ out: } /*------------------------------------------------------------------------- +* subroutine for test_text_dtype(): test_compound_bug(). Test case for +* issue 7701. +*------------------------------------------------------------------------- +*/ +static int test_compound_bug(void) +{ + hid_t dtype; + H5T_class_t type_class; + int nmembs; + char* memb_name = NULL; + char* dt_str; + size_t str_len; + char text[] = "H5T_COMPOUND { H5T_STD_I32LE \"state_________________________________________________________________________________\"; H5T_STD_I32LE \"desc_________________________________________________________________________________________\"; H5T_VLEN { H5T_COMPOUND { H5T_ENUM { H5T_STD_I16LE; \"ZERO\" 0; \"ONE\" 1; \"TWO\" 2; \"THREE\" 3; } \"type____\"; H5T_STD_I32LE \"sub_______________________________________________________________________________________________________________\"; H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_STR_SPACEPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1; } \"sub_desc\"; H5T_STD_I32LE \"final___________________________________________________________________________________________________\"; } } \"sub\"; }"; + char text2[] = + "H5T_COMPOUND {\n" + " H5T_STD_I16LE \"state___________________________" + "__________________________________________________" + "____\" : 0;\n" + " H5T_STD_I16LE \"desc____________________________" + "__________________________________________________" + "___________\" : 2;\n" + " H5T_VLEN { H5T_COMPOUND {\n" + " H5T_ENUM { H5T_STD_I16LE; \"ZERO\" 0; \"ONE\" " + "1; \"TWO\" 2; \"THREE\" 3; } \"type____\" : 0;\n" + " H5T_STD_I32LE \"sub___________________________" + "__________________________________________________" + "__________________________________1\" : 4;\n" + " H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_" + "STR_SPACEPAD; CSET H5T_CSET_ASCII; CTYPE H5T_C_S1;" + " } \"sub_desc\" : 8;\n" + " H5T_STD_I32LE \"final_________________________" + "__________________________________________________" + "________________________\" : 16;\n" + " } } \"sub\" : 8;\n" + "}\n"; + + TESTING3(" text for compound type of bug fix"); + + if((dtype = H5LTtext_to_dtype(text, H5LT_DDL))<0) + goto out; + + if((type_class = H5Tget_class(dtype))<0) + goto out; + if(type_class != H5T_COMPOUND) + goto out; + + if((memb_name = H5Tget_member_name(dtype, 2)) == NULL) + goto out; + if(strcmp(memb_name, "sub")) + goto out; + free(memb_name); + + if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0) + goto out; + + dt_str = (char*)calloc(str_len, sizeof(char)); + if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) + goto out; + free(dt_str); + + if(H5Tclose(dtype)<0) + goto out; + + + /* Test similar datatype in another format */ + if((dtype = H5LTtext_to_dtype(text2, H5LT_DDL))<0) + goto out; + + if((type_class = H5Tget_class(dtype))<0) + goto out; + if(type_class != H5T_COMPOUND) + goto out; + + if((nmembs = H5Tget_nmembers(dtype))<0) + goto out; + if(nmembs != 3) + goto out; + + if((memb_name = H5Tget_member_name(dtype, 1)) == NULL) + goto out; + if(strcmp(memb_name, "desc_________________________________________________________________________________________")) + goto out; + free(memb_name); + + if(H5LTdtype_to_text(dtype, NULL, H5LT_DDL, &str_len)<0) + goto out; + + dt_str = (char*)calloc(str_len, sizeof(char)); + if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) + goto out; + + free(dt_str); + + if(H5Tclose(dtype)<0) + goto out; + + PASSED(); + return 0; + +out: + H5_FAILED(); + return -1; +} + +/*------------------------------------------------------------------------- * subroutine for test_text_dtype(): test_complicated_compound(). *------------------------------------------------------------------------- */ @@ -1635,6 +1740,9 @@ static int test_text_dtype(void) if(test_compounds()<0) goto out; + if(test_compound_bug()<0) + goto out; + if(test_complicated_compound()<0) goto out; |