Fix more MSVC and GCC compilation warnings

This commit is contained in:
Hugues Delorme 2015-11-06 13:56:16 +01:00
parent f8c279e6db
commit 978770c161
3 changed files with 36 additions and 9 deletions

View File

@ -175,5 +175,31 @@ typedef double gmio_float64_t;
# define GMIO_C_LINKAGE_END # define GMIO_C_LINKAGE_END
#endif /* __cplusplus */ #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 */ #endif /* GMIO_GLOBAL_H */
/*! @} */ /*! @} */

View File

@ -29,6 +29,11 @@
enum { GMIO_FIXED_BUFFER_SIZE = 512 }; 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) gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream)
{ {
char fixed_buffer[GMIO_FIXED_BUFFER_SIZE] = {0}; char fixed_buffer[GMIO_FIXED_BUFFER_SIZE] = {0};
@ -55,20 +60,14 @@ gmio_stl_format_t gmio_stl_get_format(gmio_stream_t *stream)
uint32_t facet_count = uint32_t facet_count =
gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80); gmio_decode_uint32_le((const uint8_t*)fixed_buffer + 80);
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) if (gmio_stlb_streamsize(facet_count) == stream_size)
== stream_size)
{
return GMIO_STL_FORMAT_BINARY_LE; return GMIO_STL_FORMAT_BINARY_LE;
}
/* Try with byte-reverted facet count */ /* Try with big-endian format */
facet_count = gmio_uint32_bswap(facet_count); facet_count = gmio_uint32_bswap(facet_count);
if ((GMIO_STLB_HEADER_SIZE + 4 + facet_count*GMIO_STLB_TRIANGLE_RAWSIZE) if (gmio_stlb_streamsize(facet_count) == stream_size)
== stream_size)
{
return GMIO_STL_FORMAT_BINARY_BE; return GMIO_STL_FORMAT_BINARY_BE;
} }
}
/* ASCII STL ? */ /* ASCII STL ? */
{ {

View File

@ -78,9 +78,11 @@ const char* test_core__buffer()
const char* test_core__endian() const char* test_core__endian()
{ {
UTEST_ASSERT(gmio_host_endianness() == GMIO_ENDIANNESS_HOST); 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_LITTLE != GMIO_ENDIANNESS_BIG);
UTEST_ASSERT(GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_LITTLE UTEST_ASSERT(GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_LITTLE
|| GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_BIG); || GMIO_ENDIANNESS_HOST == GMIO_ENDIANNESS_BIG);
GMIO_PRAGMA_MSVC_WARNING_POP()
return NULL; return NULL;
} }