From 978770c161a0aa23f156fa72f47e9b04d1eadd28 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Fri, 6 Nov 2015 13:56:16 +0100 Subject: [PATCH] Fix more MSVC and GCC compilation warnings --- src/gmio_core/global.h | 26 ++++++++++++++++++++++++++ src/gmio_stl/stl_format.c | 17 ++++++++--------- tests/test_core.c | 2 ++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/gmio_core/global.h b/src/gmio_core/global.h index 2040975..0711671 100644 --- a/src/gmio_core/global.h +++ b/src/gmio_core/global.h @@ -175,5 +175,31 @@ typedef double gmio_float64_t; # define GMIO_C_LINKAGE_END #endif /* __cplusplus */ +#if defined(_MSC_VER) && _MSC_VER >= 1400 /* Visual C++ 2008 */ +# define GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(__code__) \ + __pragma(warning(push)) \ + __pragma(warning(disable: __code__)) +# define GMIO_PRAGMA_MSVC_WARNING_POP() \ + __pragma(warning(pop)) +#else +/*! MSVC specific macro that disable the compiler warning of code \p __code__ + * + * With Visual C++, expands to : + * \code + * #pragma warning(push) + * #pragma warning(disable: __code__) + * \endcode + */ +# define GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(__code__) +/*! MSVC specific macro that pop the changes made after last warning(pop) + * + * With Visual C++, expands to : + * \code + * #pragma warning(pop) + * \endcode + */ +# define GMIO_PRAGMA_MSVC_WARNING_POP() +#endif + #endif /* GMIO_GLOBAL_H */ /*! @} */ diff --git a/src/gmio_stl/stl_format.c b/src/gmio_stl/stl_format.c index 213881a..725e821 100644 --- a/src/gmio_stl/stl_format.c +++ b/src/gmio_stl/stl_format.c @@ -29,6 +29,11 @@ enum { GMIO_FIXED_BUFFER_SIZE = 512 }; +GMIO_INLINE gmio_streamsize_t gmio_stlb_streamsize(uint32_t facet_count) +{ + return GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE; +} + gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream) { char fixed_buffer[GMIO_FIXED_BUFFER_SIZE] = {0}; @@ -55,19 +60,13 @@ gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream) uint32_t facet_count = gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80); - if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) - == stream_size) - { + if (gmio_stlb_streamsize(facet_count) == stream_size) return GMIO_STL_FORMAT_BINARY_LE; - } - /* Try with byte-reverted facet count */ + /* Try with big-endian format */ facet_count = gmio_uint32_bswap(facet_count); - if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) - == stream_size) - { + if (gmio_stlb_streamsize(facet_count) == stream_size) return GMIO_STL_FORMAT_BINARY_BE; - } } /* ASCII STL ? */ diff --git a/tests/test_core.c b/tests/test_core.c index f5e2152..4a0a358 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -78,9 +78,11 @@ const char* test_core__buffer() const char* test_core__endian() { UTEST_ASSERT(gmio_host_endianness() == GMIO_ENDIANNESS_HOST); +GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(4127) UTEST_ASSERT(GMIO_ENDIANNESS_LITTLE != GMIO_ENDIANNESS_BIG); UTEST_ASSERT(GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_LITTLE || GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_BIG); +GMIO_PRAGMA_MSVC_WARNING_POP() return NULL; }