Fix compile warnings
This commit is contained in:
parent
4c36ab0230
commit
3b7ee5aea5
@ -25,8 +25,12 @@ done
|
||||
|
||||
|
||||
echo "int main() { return 0; }" > main.c
|
||||
gcc main.c $OUTPUT_PREFIX.c -o test.out
|
||||
gcc -ansi main.c $OUTPUT_PREFIX.c -o test.out
|
||||
gcc -Wpedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
|
||||
gcc -ansi -Wpedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
|
||||
if command -v clang
|
||||
then
|
||||
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out
|
||||
fi
|
||||
rm test.out
|
||||
rm main.c
|
||||
|
||||
|
||||
21
miniz_tdef.c
21
miniz_tdef.c
@ -1480,9 +1480,24 @@ void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int
|
||||
*pLen_out = out_buf.m_size - 41;
|
||||
{
|
||||
static const mz_uint8 chans[] = { 0x00, 0x00, 0x04, 0x02, 0x06 };
|
||||
mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0, 0, (mz_uint8)(w >> 8), (mz_uint8)w, 0, 0, (mz_uint8)(h >> 8), (mz_uint8)h, 8, chans[num_chans], 0, 0, 0, 0, 0, 0, 0,
|
||||
(mz_uint8)(*pLen_out >> 24), (mz_uint8)(*pLen_out >> 16), (mz_uint8)(*pLen_out >> 8), (mz_uint8) * pLen_out, 0x49, 0x44, 0x41, 0x54 };
|
||||
mz_uint8 pnghdr[41] = { 0x89, 0x50, 0x4e, 0x47, 0x0d,
|
||||
0x0a, 0x1a, 0x0a, 0x00, 0x00,
|
||||
0x00, 0x0d, 0x49, 0x48, 0x44,
|
||||
0x52, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x08,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x49, 0x44, 0x41,
|
||||
0x54 };
|
||||
pnghdr[18] = (mz_uint8)(w >> 8);
|
||||
pnghdr[19] = (mz_uint8)w;
|
||||
pnghdr[22] = (mz_uint8)(h >> 8);
|
||||
pnghdr[22] = (mz_uint8)h;
|
||||
pnghdr[25] = chans[num_chans];
|
||||
pnghdr[33] = (mz_uint8)(*pLen_out >> 24);
|
||||
pnghdr[34] = (mz_uint8)(*pLen_out >> 16);
|
||||
pnghdr[35] = (mz_uint8)(*pLen_out >> 8);
|
||||
pnghdr[36] = (mz_uint8)*pLen_out;
|
||||
c = (mz_uint32)mz_crc32(MZ_CRC32_INIT, pnghdr + 12, 17);
|
||||
for (i = 0; i < 4; ++i, c <<= 8)
|
||||
((mz_uint8 *)(pnghdr + 29))[i] = (mz_uint8)(c >> 24);
|
||||
|
||||
@ -568,7 +568,7 @@ tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_nex
|
||||
--pIn_buf_cur;
|
||||
num_bits -= 8;
|
||||
}
|
||||
bit_buf &= (tinfl_bit_buf_t)((1ULL << num_bits) - 1ULL);
|
||||
bit_buf &= (tinfl_bit_buf_t)(( ((mz_uint64)1) << num_bits) - (mz_uint64)1);
|
||||
MZ_ASSERT(!num_bits); /* if this assert fires then we've read beyond the end of non-deflate/zlib streams with following data (such as gzip streams). */
|
||||
|
||||
if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER)
|
||||
@ -600,7 +600,7 @@ common_exit:
|
||||
}
|
||||
}
|
||||
r->m_num_bits = num_bits;
|
||||
r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((1ULL << num_bits) - 1ULL);
|
||||
r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)(( ((mz_uint64)1) << num_bits) - (mz_uint64)1);
|
||||
r->m_dist = dist;
|
||||
r->m_counter = counter;
|
||||
r->m_num_extra = num_extra;
|
||||
|
||||
61
miniz_zip.c
61
miniz_zip.c
@ -135,8 +135,13 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||
#define MZ_FCLOSE fclose
|
||||
#define MZ_FREAD fread
|
||||
#define MZ_FWRITE fwrite
|
||||
#define MZ_FTELL64 ftello
|
||||
#define MZ_FSEEK64 fseeko
|
||||
#ifdef __STRICT_ANSI__
|
||||
#define MZ_FTELL64 ftell
|
||||
#define MZ_FSEEK64 fseek
|
||||
#else
|
||||
#define MZ_FTELL64 ftello
|
||||
#define MZ_FSEEK64 fseeko
|
||||
#endif
|
||||
#define MZ_FILE_STAT_STRUCT stat
|
||||
#define MZ_FILE_STAT stat
|
||||
#define MZ_FFLUSH fflush
|
||||
@ -741,11 +746,14 @@ static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint flag
|
||||
|
||||
do
|
||||
{
|
||||
mz_uint32 field_id;
|
||||
mz_uint32 field_data_size;
|
||||
|
||||
if (extra_size_remaining < (sizeof(mz_uint16) * 2))
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
||||
|
||||
mz_uint32 field_id = MZ_READ_LE16(pExtra_data);
|
||||
mz_uint32 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
||||
field_id = MZ_READ_LE16(pExtra_data);
|
||||
field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
||||
|
||||
if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
||||
@ -938,10 +946,11 @@ mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_
|
||||
|
||||
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size)
|
||||
{
|
||||
mz_uint64 file_size;
|
||||
|
||||
if ((!pZip) || (!pFilename) || ((archive_size) && (archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE)))
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_PARAMETER);
|
||||
|
||||
mz_uint64 file_size;
|
||||
MZ_FILE *pFile = MZ_FOPEN(pFilename, "rb");
|
||||
if (!pFile)
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_FILE_OPEN_FAILED);
|
||||
@ -1174,11 +1183,14 @@ static mz_bool mz_zip_file_stat_internal(mz_zip_archive *pZip, mz_uint file_inde
|
||||
|
||||
do
|
||||
{
|
||||
mz_uint32 field_id;
|
||||
mz_uint32 field_data_size;
|
||||
|
||||
if (extra_size_remaining < (sizeof(mz_uint16) * 2))
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
||||
|
||||
mz_uint32 field_id = MZ_READ_LE16(pExtra_data);
|
||||
mz_uint32 field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
||||
field_id = MZ_READ_LE16(pExtra_data);
|
||||
field_data_size = MZ_READ_LE16(pExtra_data + sizeof(mz_uint16));
|
||||
|
||||
if ((field_data_size + sizeof(mz_uint16) * 2) > extra_size_remaining)
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);
|
||||
@ -1969,15 +1981,15 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f
|
||||
|
||||
if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
|
||||
{
|
||||
mz_uint32 extra_size_remaining = local_header_extra_len;
|
||||
const mz_uint8 *pExtra_data = (const mz_uint8 *)file_data_array.m_p;
|
||||
|
||||
if (pZip->m_pRead(pZip->m_pIO_opaque, local_header_ofs + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + local_header_filename_len, file_data_array.m_p, local_header_extra_len) != local_header_extra_len)
|
||||
{
|
||||
mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
||||
goto handle_failure;
|
||||
}
|
||||
|
||||
mz_uint32 extra_size_remaining = local_header_extra_len;
|
||||
const mz_uint8 *pExtra_data = (const mz_uint8 *)file_data_array.m_p;
|
||||
|
||||
do
|
||||
{
|
||||
mz_uint32 field_id, field_data_size, field_total_size;
|
||||
@ -2019,6 +2031,10 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f
|
||||
if ((has_data_descriptor) && (!local_header_comp_size) && (!local_header_crc32))
|
||||
{
|
||||
mz_uint8 descriptor_buf[32];
|
||||
mz_bool has_id;
|
||||
const mz_uint8 *pSrc;
|
||||
mz_uint32 file_crc32;
|
||||
mz_uint64 comp_size = 0, uncomp_size = 0;
|
||||
|
||||
mz_uint32 num_descriptor_uint32s = ((pState->m_zip64) || (found_zip64_ext_data_in_ldir)) ? 6 : 4;
|
||||
|
||||
@ -2028,11 +2044,10 @@ mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint f
|
||||
goto handle_failure;
|
||||
}
|
||||
|
||||
mz_bool has_id = (MZ_READ_LE32(descriptor_buf) == MZ_ZIP_DATA_DESCRIPTOR_ID);
|
||||
const mz_uint8 *pSrc = has_id ? (descriptor_buf + sizeof(mz_uint32)) : descriptor_buf;
|
||||
has_id = (MZ_READ_LE32(descriptor_buf) == MZ_ZIP_DATA_DESCRIPTOR_ID);
|
||||
pSrc = has_id ? (descriptor_buf + sizeof(mz_uint32)) : descriptor_buf;
|
||||
|
||||
mz_uint32 file_crc32 = MZ_READ_LE32(pSrc);
|
||||
mz_uint64 comp_size = 0, uncomp_size = 0;
|
||||
file_crc32 = MZ_READ_LE32(pSrc);
|
||||
|
||||
if ((pState->m_zip64) || (found_zip64_ext_data_in_ldir))
|
||||
{
|
||||
@ -2622,13 +2637,12 @@ static mz_bool mz_zip_writer_add_put_buf_callback(const void *pBuf, int len, voi
|
||||
static mz_uint32 mz_zip_writer_create_zip64_extra_data(mz_uint8 *pBuf, mz_uint64 *pUncomp_size, mz_uint64 *pComp_size, mz_uint64 *pLocal_header_ofs)
|
||||
{
|
||||
mz_uint8 *pDst = pBuf;
|
||||
mz_uint32 field_size = 0;
|
||||
|
||||
MZ_WRITE_LE16(pDst + 0, MZ_ZIP64_EXTENDED_INFORMATION_FIELD_HEADER_ID);
|
||||
MZ_WRITE_LE16(pDst + 2, 0);
|
||||
pDst += sizeof(mz_uint16) * 2;
|
||||
|
||||
mz_uint32 field_size = 0;
|
||||
|
||||
if (pUncomp_size)
|
||||
{
|
||||
MZ_WRITE_LE64(pDst, *pUncomp_size);
|
||||
@ -3025,10 +3039,10 @@ mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_n
|
||||
|
||||
if (uncomp_size)
|
||||
{
|
||||
MZ_ASSERT(bit_flags & MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR);
|
||||
mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64];
|
||||
mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32;
|
||||
|
||||
mz_uint8 local_dir_footer[MZ_ZIP_DATA_DESCRIPTER_SIZE64];
|
||||
mz_uint32 local_dir_footer_size = MZ_ZIP_DATA_DESCRIPTER_SIZE32;
|
||||
MZ_ASSERT(bit_flags & MZ_ZIP_LDH_BIT_FLAG_HAS_LOCATOR);
|
||||
|
||||
MZ_WRITE_LE32(local_dir_footer + 0, MZ_ZIP_DATA_DESCRIPTOR_ID);
|
||||
MZ_WRITE_LE32(local_dir_footer + 4, uncomp_crc32);
|
||||
@ -3369,6 +3383,7 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
|
||||
mz_uint64 uncomp_size = 0;
|
||||
MZ_TIME_T file_modified_time;
|
||||
MZ_TIME_T *pFile_time = NULL;
|
||||
mz_bool status;
|
||||
|
||||
memset(&file_modified_time, 0, sizeof(file_modified_time));
|
||||
|
||||
@ -3386,7 +3401,7 @@ mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name,
|
||||
uncomp_size = MZ_FTELL64(pSrc_file);
|
||||
MZ_FSEEK64(pSrc_file, 0, SEEK_SET);
|
||||
|
||||
mz_bool status = mz_zip_writer_add_cfile(pZip, pArchive_name, pSrc_file, uncomp_size, pFile_time, pComment, comment_size, level_and_flags, NULL, 0, NULL, 0);
|
||||
status = mz_zip_writer_add_cfile(pZip, pArchive_name, pSrc_file, uncomp_size, pFile_time, pComment, comment_size, level_and_flags, NULL, 0, NULL, 0);
|
||||
|
||||
MZ_FCLOSE(pSrc_file);
|
||||
|
||||
@ -3558,6 +3573,9 @@ mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *
|
||||
if ((local_header_extra_len) && ((local_header_comp_size == MZ_UINT32_MAX) || (local_header_uncomp_size == MZ_UINT32_MAX)))
|
||||
{
|
||||
mz_zip_array file_data_array;
|
||||
const mz_uint8 *pExtra_data;
|
||||
mz_uint32 extra_size_remaining = local_header_extra_len;
|
||||
|
||||
mz_zip_array_init(&file_data_array, 1);
|
||||
if (!mz_zip_array_resize(pZip, &file_data_array, local_header_extra_len, MZ_FALSE))
|
||||
{
|
||||
@ -3570,8 +3588,7 @@ mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *
|
||||
return mz_zip_set_error(pZip, MZ_ZIP_FILE_READ_FAILED);
|
||||
}
|
||||
|
||||
mz_uint32 extra_size_remaining = local_header_extra_len;
|
||||
const mz_uint8 *pExtra_data = (const mz_uint8 *)file_data_array.m_p;
|
||||
pExtra_data = (const mz_uint8 *)file_data_array.m_p;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user