From 4010dff058d8fc88d602e3bc231a6558599b89f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Sat, 14 Sep 2024 11:05:44 +0300 Subject: [PATCH] mtr_t::log_file_op(): Fix -Wnonnull GCC 12.2.0 could issue -Wnonnull for an unreachable call to strlen(new_path). Let us prevent that by replacing the condition (type == FILE_RENAME) with the equivalent (new_path). This should also optimize the generated code, because the life time of the parameter "type" will be reduced. --- storage/innobase/fil/fil0fil.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index ba4fbc49204..514d6f51fff 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1554,17 +1554,18 @@ inline void mtr_t::log_file_op(mfile_type_t type, ulint space_id, m_last= nullptr; const size_t len= strlen(path); - const size_t new_len= type == FILE_RENAME ? 1 + strlen(new_path) : 0; + const size_t new_len= new_path ? 1 + strlen(new_path) : 0; ut_ad(len > 0); byte *const log_ptr= m_log.open(1 + 3/*length*/ + 5/*space_id*/ + 1/*page_no=0*/); + *log_ptr= type; byte *end= log_ptr + 1; end= mlog_encode_varint(end, space_id); *end++= 0; - if (UNIV_LIKELY(end + len + new_len >= &log_ptr[16])) + const byte *const final_end= end + len + new_len; + if (UNIV_LIKELY(final_end >= &log_ptr[16])) { - *log_ptr= type; - size_t total_len= len + new_len + end - log_ptr - 15; + size_t total_len= final_end - log_ptr - 15; if (total_len >= MIN_3BYTE) total_len+= 2; else if (total_len >= MIN_2BYTE) @@ -1575,13 +1576,13 @@ inline void mtr_t::log_file_op(mfile_type_t type, ulint space_id, } else { - *log_ptr= static_cast(type | (end + len + new_len - &log_ptr[1])); + *log_ptr= static_cast(*log_ptr | (final_end - &log_ptr[1])); ut_ad(*log_ptr & 15); } m_log.close(end); - if (type == FILE_RENAME) + if (new_path) { ut_ad(strchr(new_path, OS_PATH_SEPARATOR)); m_log.push(reinterpret_cast(path), uint32_t(len + 1));