activate -Wcast-qual and fix warnings

This commit is contained in:
Daniel Mendler 2019-01-30 12:47:38 +01:00
parent f3461d636a
commit deb9f85a19
No known key found for this signature in database
GPG Key ID: D88ADB2A2693CA43
3 changed files with 17 additions and 15 deletions

View File

@ -23,20 +23,22 @@ do
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c
done done
WARNINGS="-Wall -Wcast-qual"
echo "int main() { return 0; }" > main.c echo "int main() { return 0; }" > main.c
echo "Test compile with GCC..." echo "Test compile with GCC..."
gcc -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out gcc -pedantic $WARNINGS main.c $OUTPUT_PREFIX.c -o test.out
echo "Test compile with GCC ANSI..." echo "Test compile with GCC ANSI..."
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out gcc -ansi -pedantic $WARNINGS main.c $OUTPUT_PREFIX.c -o test.out
if command -v clang if command -v clang
then then
echo "Test compile with clang..." echo "Test compile with clang..."
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out clang $WARNINGS -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out
fi fi
for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC
do do
echo "Test compile with GCC and define $def..." echo "Test compile with GCC and define $def..."
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out -D${def} gcc -ansi -pedantic $WARNINGS main.c $OUTPUT_PREFIX.c -o test.out -D${def}
done done
rm test.out rm test.out
rm main.c rm main.c
@ -65,5 +67,3 @@ EOF
cd .. cd ..
echo "Amalgamation created." echo "Amalgamation created."

View File

@ -1498,7 +1498,7 @@ void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int
for (y = 0; y < h; ++y) for (y = 0; y < h; ++y)
{ {
tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH);
tdefl_compress_buffer(pComp, (mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH); tdefl_compress_buffer(pComp, (const mz_uint8 *)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH);
} }
if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE)
{ {

View File

@ -929,6 +929,11 @@ static size_t mz_zip_mem_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf
mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags) mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags)
{ {
union {
void* pMut;
const void* pConst;
} ptr_const_cast;
if (!pMem) if (!pMem)
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER); return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
@ -944,11 +949,8 @@ mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t si
pZip->m_pIO_opaque = pZip; pZip->m_pIO_opaque = pZip;
pZip->m_pNeeds_keepalive = NULL; pZip->m_pNeeds_keepalive = NULL;
#ifdef __cplusplus ptr_const_cast.pConst = pMem;
pZip->m_pState->m_pMem = const_cast<void *>(pMem); pZip->m_pState->m_pMem = ptr_const_cast.pMut;
#else
pZip->m_pState->m_pMem = (void *)pMem;
#endif
pZip->m_pState->m_mem_size = size; pZip->m_pState->m_mem_size = size;
@ -3239,8 +3241,8 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
if (!pState->m_zip64) if (!pState->m_zip64)
{ {
/* Bail early if the archive would obviously become too large */ /* Bail early if the archive would obviously become too large */
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size
+ MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len + + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size + user_extra_data_len +
pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + user_extra_data_central_len
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF) + MZ_ZIP_DATA_DESCRIPTER_SIZE32) > 0xFFFFFFFF)
{ {
@ -3498,7 +3500,7 @@ mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pA
if (!pState->m_zip64) if (!pState->m_zip64)
{ {
/* Bail early if the archive would obviously become too large */ /* Bail early if the archive would obviously become too large */
if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE if ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + archive_name_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE
+ archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024 + archive_name_size + comment_size + user_extra_data_len + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE + 1024
+ MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF) + MZ_ZIP_DATA_DESCRIPTER_SIZE32 + user_extra_data_central_len) > 0xFFFFFFFF)
{ {