]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Avoid undefined behaviour in build_option_suggestions
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Fri, 19 Jul 2024 16:44:32 +0000 (12:44 -0400)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Sat, 20 Jul 2024 11:53:23 +0000 (07:53 -0400)
The inner loop in build_option_suggestions uses OPTION to take the
address of OPTB and use it across iterations, which is undefined
behaviour since OPTB is defined within the loop.  Pull it outside the
loop to make this defined.

gcc/ChangeLog:

* opt-suggestions.cc
(option_proposer::build_option_suggestions): Pull OPTB
definition out of the innermost loop.

gcc/opt-suggestions.cc

index 849e4f5c43900b589d452c7edbb81169eb7fa845..71e5cb561a69d7a3b5e55eec082ef61c4065bf18 100644 (file)
@@ -167,9 +167,9 @@ option_proposer::build_option_suggestions (const char *prefix)
            add_misspelling_candidates (m_option_suggestions, option,
                                        opt_text);
 
+           struct cl_option optb;
            for (int j = 0; sanitizer_opts[j].name != NULL; ++j)
              {
-               struct cl_option optb;
                /* -fsanitize=all is not valid, only -fno-sanitize=all.
                   So don't register the positive misspelling candidates
                   for it.  */