[minizip-ng] Fix some warnings that broke -Werror builds.

Initialize some variables, and use memcpy() instead of strncpy().

Remove the -Wno-error options. This broke on Debian 8 ppc (gcc-4.9.2),
which doesn't support -Wstringop-overflow or -Wstringop-truncation.

extlib/minizip-ng/compat/unzip.c: In function ‘unzGetFilePos’:
extlib/minizip-ng/compat/unzip.c:563:38: error: ‘file_pos64.pos_in_zip_directory’ may be used uninitialized [-Werror=maybe-uninitialized]
  563 |     file_pos->pos_in_zip_directory = (uint32_t)file_pos64.pos_in_zip_directory;
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extlib/minizip-ng/compat/unzip.c:556:20: note: ‘file_pos64.pos_in_zip_directory’ was declared here
  556 |     unz64_file_pos file_pos64;
      |                    ^~~~~~~~~~
extlib/minizip-ng/compat/unzip.c:564:29: error: ‘file_pos64.num_of_file’ may be used uninitialized [-Werror=maybe-uninitialized]
  564 |     file_pos->num_of_file = (uint32_t)file_pos64.num_of_file;
      |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
extlib/minizip-ng/compat/unzip.c:556:20: note: ‘file_pos64.num_of_file’ was declared here
  556 |     unz64_file_pos file_pos64;
      |                    ^~~~~~~~~~
cc1: all warnings being treated as errors

extlib/minizip-ng/mz_zip.c: In function ‘mz_zip_set_comment’:
extlib/minizip-ng/mz_zip.c:1569:5: error: ‘__builtin___strncpy_chk’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
 1569 |     strncpy(zip->comment, comment, comment_size);
      |     ^
extlib/minizip-ng/mz_zip.c:1563:29: note: length computed here
 1563 |     comment_size = (int32_t)strlen(comment);
      |                             ^~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
This commit is contained in:
David Korth 2025-04-07 20:55:55 -04:00
parent b18e8b2fcd
commit d1ff987d64
3 changed files with 3 additions and 7 deletions

View File

@ -39,11 +39,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
message(STATUS "Using CMake version ${CMAKE_VERSION}")
# rom-properties: FIXME: Fix these warnings.
IF(NOT MSVC)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=stringop-overflow -Wno-error=stringop-truncation -Wno-error=maybe-uninitialized")
ENDIF(NOT MSVC)
# rom-properties: Disabled these options.
IF(0)
# Compatibility options

View File

@ -553,7 +553,7 @@ int unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filena
/***************************************************************************/
int unzGetFilePos(unzFile file, unz_file_pos *file_pos) {
unz64_file_pos file_pos64;
unz64_file_pos file_pos64 = {0, 0};
int32_t err = 0;
err = unzGetFilePos64(file, &file_pos64);

View File

@ -1566,7 +1566,8 @@ int32_t mz_zip_set_comment(void *handle, const char *comment) {
zip->comment = (char *)calloc(comment_size + 1, sizeof(char));
if (!zip->comment)
return MZ_MEM_ERROR;
strncpy(zip->comment, comment, comment_size);
// using memcpy() instead of strncpy() to avoid -Werror=stringop-truncation
memcpy(zip->comment, comment, comment_size + 1);
return MZ_OK;
}