From 035e9c2ba6e7462c8ba2c7c7880308c25a01a7bb Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Mon, 14 Sep 2015 17:30:22 +0200 Subject: [PATCH] tests: fix failure of test test_stlb_write() Compiler: GCC v4.9.2 OS : linux-x64 --- tests/stl_utils.c | 4 ++-- tests/stl_utils.h | 6 +++++- tests/test_stl_io.c | 9 +++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/stl_utils.c b/tests/stl_utils.c index 15895b3..362e1da 100644 --- a/tests/stl_utils.c +++ b/tests/stl_utils.c @@ -36,7 +36,7 @@ gmio_stl_triangle_array_t gmio_stl_triangle_array_malloc(size_t tri_count) gmio_stl_triangle_array_t array = {0}; if (tri_count > 0) { array.ptr = - (gmio_stl_triangle_t*)malloc(tri_count * sizeof(gmio_stl_triangle_t)); + (gmio_stl_triangle_t*)calloc(tri_count, sizeof(gmio_stl_triangle_t)); } array.count = gmio_size_to_uint32(tri_count); array.capacity = array.count; @@ -83,7 +83,7 @@ static void gmio_stl_data__add_triangle( realloc(data->tri_array.ptr, cap * sizeof(gmio_stl_triangle_t)); data->tri_array.capacity = cap; } - data->tri_array.ptr[tri_id] = *triangle; + memcpy(&data->tri_array.ptr[tri_id], triangle, GMIO_STLB_TRIANGLE_RAWSIZE); data->tri_array.count = GMIO_MAX(data->tri_array.count, tri_id + 1); } diff --git a/tests/stl_utils.h b/tests/stl_utils.h index 0dc616a..248517e 100644 --- a/tests/stl_utils.h +++ b/tests/stl_utils.h @@ -62,7 +62,11 @@ struct gmio_stl_triangle_array }; typedef struct gmio_stl_triangle_array gmio_stl_triangle_array_t; -/*! Returns an dynamically allocated array of gmio_stl_triangle_t */ +/*! Returns an dynamically allocated array of gmio_stl_triangle_t + * + * Contents of the memory block beginnning at gmio_stl_triangle_array::ptr + * is initialized with zeroes + */ gmio_stl_triangle_array_t gmio_stl_triangle_array_malloc(size_t tri_count); /*! Holds complete STL data (usable for both binary and ascii formats) */ diff --git a/tests/test_stl_io.c b/tests/test_stl_io.c index 3ece2a2..87453c4 100644 --- a/tests/test_stl_io.c +++ b/tests/test_stl_io.c @@ -265,15 +265,16 @@ const char* test_stlb_write() /* Check output LE/BE models are equal */ { - const uint32_t le_tri_count = data.tri_array.count; - const gmio_stl_triangle_t* le_tri_ptr = data.tri_array.ptr; gmio_stl_data_t data_be = {0}; gmio_stl_mesh_creator_t creator = gmio_stl_data_mesh_creator(&data_be); error = gmio_stl_read_file(model_filepath_out_be, &creator, NULL); UTEST_ASSERT(error == GMIO_ERROR_OK); UTEST_ASSERT(gmio_stlb_header_equal(&data.header, &data_be.header)); - UTEST_ASSERT(le_tri_count == data_be.tri_array.count); - UTEST_ASSERT(memcmp(le_tri_ptr, data_be.tri_array.ptr, le_tri_count) == 0); + UTEST_ASSERT(data.tri_array.count == data_be.tri_array.count); + UTEST_ASSERT(memcmp(data.tri_array.ptr, + data_be.tri_array.ptr, + data.tri_array.count * sizeof(gmio_stl_triangle_t)) + == 0); free(data_be.tri_array.ptr); }