Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: ignore maybe-uninitialized warning string_search
Currently, the following compilation warning is generated with GCC
version 8.2.1:

In file included from ../src/node_buffer.cc:29:
../src/string_search.h:
In function ‘size_t node::stringsearch::SearchString(
    node::stringsearch::Vector<const Char>,
    node::stringsearch::Vector<const Char>,
    size_t) [with Char = short unsigned int]’:
../src/string_search.h:113:30: warning:
‘search’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
     return (this->*strategy_)(subject, index);
            ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~

../src/string_search.h:
In function ‘size_t node::stringsearch::SearchString(
    node::stringsearch::Vector<const Char>,
    node::stringsearch::Vector<const Char>,
    size_t) [with Char = unsigned char]’:
../src/string_search.h:113:30:
warning: ‘search’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
     return (this->*strategy_)(subject, index);
            ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~

The issue here seems to be with the `strategy_` field which is a pointer
to a member function, and it is set in the constructor of StringSearch.
It is always set and I've not been able to work around this warning
so this commit suggests adding a pragma for GCC to ignore the warning.
  • Loading branch information
danbev committed Jan 27, 2020
commit b520c74dfd3cd164549dd89ec020dbdc662d9589
7 changes: 7 additions & 0 deletions src/string_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ class StringSearch : private StringSearchBase {
}

size_t Search(Vector subject, size_t index) {
#if (__GNUC__ >= 8) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
return (this->*strategy_)(subject, index);
#if (__GNUC__ >= 8) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the issue is not with strategy_, but with the arrays in the StringSearchBase, which are indeed uninitialized (they will be initialized before BoyerMoore search is started)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lundibundi Thanks, I'll try to take a closer look at this again this week.

}

static inline int AlphabetSize() {
Expand Down