diff --git a/src/gmio_stl/internal/stla_infos_probe.c b/src/gmio_stl/internal/stla_infos_probe.c index 3aaab3b..65fbcdf 100644 --- a/src/gmio_stl/internal/stla_infos_probe.c +++ b/src/gmio_stl/internal/stla_infos_probe.c @@ -96,6 +96,8 @@ int gmio_stla_infos_probe( if (flags == 0) return err; + if (flag_stla_solidname && infos->stla_solidname == NULL) + return GMIO_STL_ERROR_INFO_NULL_SOLIDNAME; if (!gmio_check_memblock(&err, &opts->stream_memblock)) return err; @@ -127,18 +129,17 @@ int gmio_stla_infos_probe( gmio_stla_parse_solidname_beg(&parse_data); /* Copy parsed solid name into infos->stla_solid_name */ - { - const struct gmio_string* strbuff = &parse_data.token_str; - const size_t name_len_for_cpy = - GMIO_MIN(infos->stla_solidname_maxlen - 1, strbuff->len); + const struct gmio_string* strbuff = &parse_data.token_str; + const size_t name_len_for_cpy = + GMIO_MIN(infos->stla_solidname_maxlen - 1, strbuff->len); + + strncpy(infos->stla_solidname, strbuff->ptr, name_len_for_cpy); + /* Null terminate C string */ + if (name_len_for_cpy != 0) + infos->stla_solidname[name_len_for_cpy] = '\0'; + else if (infos->stla_solidname_maxlen != 0) + infos->stla_solidname[0] = '\0'; - strncpy(infos->stla_solidname, strbuff->ptr, name_len_for_cpy); - /* Null terminate C string */ - if (name_len_for_cpy != 0) - infos->stla_solidname[name_len_for_cpy] = 0; - else if (infos->stla_solidname_maxlen != 0) - infos->stla_solidname[0] = 0; - } sstream = parse_data.strstream; } diff --git a/src/gmio_stl/stl_error.h b/src/gmio_stl/stl_error.h index cecad72..4475c02 100644 --- a/src/gmio_stl/stl_error.h +++ b/src/gmio_stl/stl_error.h @@ -48,27 +48,33 @@ enum gmio_stl_error /*! Common STL write error indicating gmio_stl_mesh::func_get_triangle() * pointer is NULL */ - GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE = GMIO_STL_ERROR_TAG + 0x02, + GMIO_STL_ERROR_NULL_FUNC_GET_TRIANGLE, /* Specific error codes returned by STL_ascii read function */ /*! Parsing error occured due to malformed STL ascii input */ - GMIO_STL_ERROR_PARSING = GMIO_STL_ERROR_TAG + 0x100, + GMIO_STL_ERROR_PARSING, /*! Invalid max number of decimal significants digits must be in [1..9] */ - GMIO_STL_ERROR_INVALID_FLOAT32_PREC = GMIO_STL_ERROR_TAG + 0x101, + GMIO_STL_ERROR_INVALID_FLOAT32_PREC, /* Specific error codes returned by STL_binary read/write functions */ /*! The byte order argument supplied is not supported, must be little or * big endian */ - GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER = GMIO_STL_ERROR_TAG + 0x1000, + GMIO_STL_ERROR_UNSUPPORTED_BYTE_ORDER, /*! Error occured when reading header data in gmio_stlb_read() */ - GMIO_STL_ERROR_HEADER_WRONG_SIZE = GMIO_STL_ERROR_TAG + 0x1001, + GMIO_STL_ERROR_HEADER_WRONG_SIZE, /*! Error occured when reading facet count in gmio_stlb_read() */ - GMIO_STL_ERROR_FACET_COUNT = GMIO_STL_ERROR_TAG + 0x1002 + GMIO_STL_ERROR_FACET_COUNT, + + /* Specific error codes returned by STL infos probe functions */ + + /*! Flag \c GMIO_STLA_INFO_FLAG_SOLIDNAME is on but supplied + * gmio_stl_infos::stla_solidname string is NULL */ + GMIO_STL_ERROR_INFO_NULL_SOLIDNAME }; /*! @} */ diff --git a/tests/main_test_stl.c b/tests/main_test_stl.c index e810b38..7d07966 100644 --- a/tests/main_test_stl.c +++ b/tests/main_test_stl.c @@ -61,6 +61,7 @@ const char* all_tests() UTEST_RUN(test_stl_internal__error_check); UTEST_RUN(test_stl_infos); + UTEST_RUN(test_stl_infos_github8); UTEST_RUN(test_stl_read); UTEST_RUN(test_stl_read_multi_solid); diff --git a/tests/test_stl_infos.c b/tests/test_stl_infos.c index cd1ea18..80cd2e4 100644 --- a/tests/test_stl_infos.c +++ b/tests/test_stl_infos.c @@ -101,3 +101,14 @@ static const char* test_stl_infos() } return NULL; } + +static const char* test_stl_infos_github8() +{ + const char* filepath = "models/solid_empty.stla"; + struct gmio_stl_infos infos = {0}; + infos.stla_solidname_maxlen = 512; + const int error = gmio_stl_infos_probe_file( + &infos, filepath, GMIO_STL_INFO_FLAG_ALL, NULL); + UTEST_COMPARE_INT(error, GMIO_STL_ERROR_INFO_NULL_SOLIDNAME); + return NULL; +}