From d67320e06aeccbb9fe4a2e0d7115222c17434032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 20 Apr 2018 23:08:57 +0300 Subject: [PATCH] Fix more GCC 8 build failures Fixed string truncation warnings by reducing max parameter lengths by one where applicable. The binlogrouter filename lengths are slightly different so using memcpy to work around the warnings is an adequate "solution" until the root of the problem is solved. Removed unnecessary CMake policy settings from qc_sqlite. Adding a self-dependency on the source file of an external project has no effect and only caused warnings to be logged. --- query_classifier/qc_sqlite/CMakeLists.txt | 5 ----- server/core/config.cc | 3 ++- server/core/internal/skygw_utils.h | 6 +++--- server/inih/ini.c | 4 ++-- server/modules/routing/binlogrouter/blr_file.c | 4 ++-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/query_classifier/qc_sqlite/CMakeLists.txt b/query_classifier/qc_sqlite/CMakeLists.txt index 59c82a1ac..345e48610 100644 --- a/query_classifier/qc_sqlite/CMakeLists.txt +++ b/query_classifier/qc_sqlite/CMakeLists.txt @@ -1,7 +1,3 @@ -if(NOT ${CMAKE_VERSION} VERSION_LESS 3.0.0) - cmake_policy(SET CMP0046 OLD) -endif() - include(ExternalProject) ExternalProject_Add(maxscale_sqlite @@ -10,7 +6,6 @@ ExternalProject_Add(maxscale_sqlite CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sqlite-src-3110100/configure --with-pic --enable-maxscale BUILD_COMMAND make sqlite3.c INSTALL_COMMAND "") -add_dependencies(maxscale_sqlite ${CMAKE_CURRENT_SOURCE_DIR}/sqlite-src-3110100/src/parse.y) include_directories(${CMAKE_BINARY_DIR}/sqlite-bld-3110100/tsrc) include_directories(${CMAKE_BINARY_DIR}/sqlite-bld-3110100) diff --git a/server/core/config.cc b/server/core/config.cc index ff41c2875..469d65482 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -2537,7 +2537,8 @@ config_get_release_string(char* release) } have_distribution = true; - strncpy(release, new_to, RELEASE_STR_LENGTH); + strncpy(release, new_to, RELEASE_STR_LENGTH - 1); + release[RELEASE_STR_LENGTH - 1] = '\0'; } } } diff --git a/server/core/internal/skygw_utils.h b/server/core/internal/skygw_utils.h index 1c4b6e85c..6fca7cc1c 100644 --- a/server/core/internal/skygw_utils.h +++ b/server/core/internal/skygw_utils.h @@ -46,12 +46,12 @@ typedef enum { MES_RC_FAIL, MES_RC_SUCCESS, MES_RC_TIMEOUT } skygw_mes_rc_t; static const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d "; /** One for terminating '\0' */ -static const size_t timestamp_len = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 3 + 1) * sizeof(char); +static const size_t timestamp_len = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 3 + 1 + 16) * sizeof(char); static const char* timestamp_formatstr_hp = "%04d-%02d-%02d %02d:%02d:%02d.%03d "; /** One for terminating '\0' */ -static const size_t timestamp_len_hp = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 3 + 3 + 1) * sizeof( - char); +static const size_t timestamp_len_hp = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 3 + 3 + 1 + 16) * + sizeof(char); struct skygw_thread_st { diff --git a/server/inih/ini.c b/server/inih/ini.c index 9f9110eaf..ac185fb55 100644 --- a/server/inih/ini.c +++ b/server/inih/ini.c @@ -117,7 +117,7 @@ int ini_parse_file(FILE* file, end = find_char_or_comment(start + 1, ']'); if (*end == ']') { *end = '\0'; - strncpy0(section, start + 1, sizeof(section)); + strncpy0(section, start + 1, sizeof(section) - 1); *prev_name = '\0'; } else if (!error) { @@ -141,7 +141,7 @@ int ini_parse_file(FILE* file, rstrip(value); /* Valid name[=:]value pair found, call handler */ - strncpy0(prev_name, name, sizeof(prev_name)); + strncpy0(prev_name, name, sizeof(prev_name) - 1); if (!handler(user, section, name, value) && !error) error = lineno; } diff --git a/server/modules/routing/binlogrouter/blr_file.c b/server/modules/routing/binlogrouter/blr_file.c index 8561621d4..81cc564c2 100644 --- a/server/modules/routing/binlogrouter/blr_file.c +++ b/server/modules/routing/binlogrouter/blr_file.c @@ -1669,7 +1669,7 @@ blr_file_next_exists(ROUTER_INSTANCE *router, sprintf(buf, BINLOG_NAMEFMT, router->fileroot, filenum + 1); sprintf(bigbuf, "%s/%s", router->binlogdir, buf); // Set the new file name in the output - strncpy(next_file, buf, BINLOG_FNAMELEN); + memcpy(next_file, buf, BINLOG_FNAMELEN); next_file[BINLOG_FNAMELEN] = '\0'; } else @@ -1712,7 +1712,7 @@ blr_file_next_exists(ROUTER_INSTANCE *router, result.gtid_elms.server_id, result.file); // Set the new file name in the output - strncpy(next_file, result.file, BINLOG_FNAMELEN); + memcpy(next_file, result.file, BINLOG_FNAMELEN); next_file[BINLOG_FNAMELEN] = '\0'; MXS_DEBUG("The next Binlog file from GTID maps repo is [%s]",