From b7832bb33d152e89a9607f4ec0726eef7f5849c3 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 30 Mar 2017 11:02:47 +0200 Subject: [PATCH] Fix most of GCC and MSVC warnings --- benchmarks/benchmark_gmio/main.c | 4 +-- src/gmio_amf/amf_io.c | 10 +++--- src/gmio_core/internal/zlib_utils.c | 14 ++++++++ src/gmio_core/internal/zlib_utils.h | 8 +++++ tests/test_amf_io.c | 52 +++++++++++++-------------- tests/test_core_benchmark_fast_atof.c | 1 + 6 files changed, 55 insertions(+), 34 deletions(-) diff --git a/benchmarks/benchmark_gmio/main.c b/benchmarks/benchmark_gmio/main.c index 3e41286..0af52a1 100644 --- a/benchmarks/benchmark_gmio/main.c +++ b/benchmarks/benchmark_gmio/main.c @@ -242,7 +242,7 @@ void bmk_gmio_stl_infos_probe_all(const void* filepath) " Size: %uKo\n" " Facets: %u\n", cfilepath, - infos.size / 1024, + (unsigned)infos.size / 1024, infos.facet_count); if (infos.format == GMIO_STL_FORMAT_ASCII) printf(" [STLA]Solid name: %s\n", infos.stla_solidname); @@ -264,7 +264,7 @@ void bmk_gmio_stl_infos_probe_size(const void* filepath) " File: %s\n" " Size: %uKo\n", cfilepath, - infos.size / 1024); + (unsigned)infos.size / 1024); } already_exec = true; } diff --git a/src/gmio_amf/amf_io.c b/src/gmio_amf/amf_io.c index 41a5515..580dd34 100644 --- a/src/gmio_amf/amf_io.c +++ b/src/gmio_amf/amf_io.c @@ -633,22 +633,20 @@ static size_t gmio_amf_ostringstream_write_zlib( const char* ptr, size_t len) { + const uint8_t* ptr_u8 = (const uint8_t*)ptr; struct gmio_memblock* z_mblock = &context->z_memblock; struct z_stream_s* z_stream = &context->z_stream; size_t total_written_len = 0; int z_retcode = Z_OK; context->z_uncompressed_size += len; - context->z_crc32 = - gmio_zlib_crc32_update(context->z_crc32, (const uint8_t*)ptr, len); + context->z_crc32 = gmio_zlib_crc32_update(context->z_crc32, ptr_u8, len); - z_stream->next_in = (z_const Bytef*)ptr; - z_stream->avail_in = len; + gmio_zlib_assign_zstream_in(z_stream, ptr_u8, len); /* Run zlib deflate() on input until output buffer not full * Finish compression when zflush == Z_FINISH */ do { - z_stream->next_out = z_mblock->ptr; - z_stream->avail_out = z_mblock->size; + gmio_zlib_assign_zstream_out(z_stream, z_mblock->ptr, z_mblock->size); z_retcode = deflate(z_stream, context->z_flush); /* Check state not clobbered */ if (z_retcode == Z_STREAM_ERROR) { diff --git a/src/gmio_core/internal/zlib_utils.c b/src/gmio_core/internal/zlib_utils.c index e3b5acb..42017df 100644 --- a/src/gmio_core/internal/zlib_utils.c +++ b/src/gmio_core/internal/zlib_utils.c @@ -162,3 +162,17 @@ uint32_t gmio_zlib_crc32_initial() { return crc32(0, NULL, 0); } + +void gmio_zlib_assign_zstream_in( + struct z_stream_s *zstream, const uint8_t *next_in, size_t avail_in) +{ + zstream->next_in = (z_const Bytef*)next_in; + zstream->avail_in = (uInt)avail_in; +} + +void gmio_zlib_assign_zstream_out( + struct z_stream_s *zstream, uint8_t *next_out, size_t avail_out) +{ + zstream->next_out = next_out; + zstream->avail_out = (uInt)avail_out; +} diff --git a/src/gmio_core/internal/zlib_utils.h b/src/gmio_core/internal/zlib_utils.h index 9894d78..8f9a43e 100644 --- a/src/gmio_core/internal/zlib_utils.h +++ b/src/gmio_core/internal/zlib_utils.h @@ -62,3 +62,11 @@ uint32_t gmio_zlib_crc32_initial(); /*! Updates a running CRC-32 with the bytes from \p buff */ uint32_t gmio_zlib_crc32_update( uint32_t crc, const uint8_t* buff, size_t buff_len); + +/*! Type-safe assigns z_stream_s::next_in and z_stream_s::avail_in */ +void gmio_zlib_assign_zstream_in( + struct z_stream_s* zstream, const uint8_t* next_in, size_t avail_in); + +/*! Type-safe assigns z_stream_s::next_out and z_stream_s::avail_out */ +void gmio_zlib_assign_zstream_out( + struct z_stream_s* zstream, uint8_t* next_out, size_t avail_out); diff --git a/tests/test_amf_io.c b/tests/test_amf_io.c index 6c78551..07b5542 100644 --- a/tests/test_amf_io.c +++ b/tests/test_amf_io.c @@ -208,37 +208,37 @@ const struct __tamf__material __tamf__doc_1_materials[] = { }; const struct gmio_vec3d __tamf__doc_1_vertices[] = { - { 0., 0., 0.}, - { 1., 0., 0.}, - { 1., -1., 0.}, - { 0., -1., 0.}, - { 1., 0., 1.}, - { 1., -1., 1.}, - { 0., 0., 1.}, - { 0., -1., 1.} + { 0., 0., 0. }, + { 1., 0., 0. }, + { 1., -1., 0. }, + { 0., -1., 0. }, + { 1., 0., 1. }, + { 1., -1., 1. }, + { 0., 0., 1. }, + { 0., -1., 1. } }; const struct __tamf__triangle __tamf__doc_1_triangles[] = { - { 0, 1, 2}, - { 0, 2, 3}, - { 1, 5, 2}, - { 1, 4, 5}, - { 6, 5, 7}, - { 6, 4, 5}, - { 0, 6, 7}, - { 0, 7, 3}, - { 0, 6, 4}, - { 0, 4, 1}, - { 3, 7, 5}, - { 3, 5, 2} + { {0, 1, 2} }, + { {0, 2, 3} }, + { {1, 5, 2} }, + { {1, 4, 5} }, + { {6, 5, 7} }, + { {6, 4, 5} }, + { {0, 6, 7} }, + { {0, 7, 3} }, + { {0, 6, 4} }, + { {0, 4, 1} }, + { {3, 7, 5} }, + { {3, 5, 2} } }; const struct gmio_amf_instance __tamf__doc_1_instances[] = { - { 0, {0}, {0} }, - { 1, {10, 0, 0}, { 45, 0, 0} }, - { 2, {0, 10, 0}, { 0, 45, 0} }, - { 3, {0, 0, 10}, { 0, 0, 45} }, - { 4, {10, 10, 0}, { 45, 45, 0} }, + { 0, {0, 0, 0}, {0, 0, 0} }, + { 1, {10, 0, 0}, {45, 0, 0} }, + { 2, {0, 10, 0}, {0, 45, 0} }, + { 3, {0, 0, 10}, {0, 0, 45} }, + { 4, {10, 10, 0}, {45, 45, 0} }, }; struct __tamf__document __tamf__create_doc_1() @@ -382,7 +382,7 @@ static const char* test_amf_write_doc_1_zip() size_t dest_len = amf_data_len; ptr_g_memblock += dest_len; const uint8_t* amf_zdata = (const uint8_t*)wbuff.ptr + wbuff.pos; - const int error = gmio_zlib_uncompress_buffer( + error = gmio_zlib_uncompress_buffer( dest, &dest_len, amf_zdata, amf_zdata_len); printf("\ninfo: z_len=%u src_len=%u\n", (unsigned)amf_zdata_len, (unsigned)amf_data_len); diff --git a/tests/test_core_benchmark_fast_atof.c b/tests/test_core_benchmark_fast_atof.c index ad10bea..43e4af6 100644 --- a/tests/test_core_benchmark_fast_atof.c +++ b/tests/test_core_benchmark_fast_atof.c @@ -68,6 +68,7 @@ static void __tc__run_atof(float (*func_atof)(const char*)) fres = func_atof(strbuff); gmio_snprintf(strbuff, sizeof(strbuff), "%E", f); fres = func_atof(strbuff); + GMIO_UNUSED(fres); } } }