From 9697fac5e11a7ba19b2b1888eb568b0c6b6a2409 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Fri, 14 Feb 2020 10:16:37 -0800 Subject: [PATCH] src: fix StringSearch compiler warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit StringSearchBase has tables (int array members) that are used only for some search strategies, but g++-9 (at least) doesn't understand when they will or will not be used. Default-initialize them in the constructor to avoid this warning: In file included from ../../src/node_buffer.cc:29: ../../src/string_search.h: In function ‘size_t node::stringsearch::SearchString(node::stringsearch::Vector, node::stringsearch::Vector, size_t) [with Char = short unsigned int]’: ../../src/string_search.h:113:30: warning: ‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized] 113 | return (this->*strategy_)(subject, index); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ ../../src/string_search.h: In function ‘size_t node::stringsearch::SearchString(node::stringsearch::Vector, node::stringsearch::Vector, size_t) [with Char = unsigned char]’: ../../src/string_search.h:113:30: warning: ‘search’ may be used uninitialized in this function [-Wmaybe-uninitialized] 113 | return (this->*strategy_)(subject, index); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ --- src/string_search.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/string_search.h b/src/string_search.h index b339c355fe168d..5daa0ec8243128 100644 --- a/src/string_search.h +++ b/src/string_search.h @@ -55,6 +55,9 @@ class Vector { // independently of subject and pattern char size. class StringSearchBase { protected: + StringSearchBase() : bad_char_shift_table_(), good_suffix_shift_table_(), + suffix_table_() {} + // Cap on the maximal shift in the Boyer-Moore implementation. By setting a // limit, we can fix the size of tables. For a needle longer than this limit, // search will not be optimal, since we only build tables for a suffix