]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++/regex: Zero-initialize _ExecutorFrame flags
authorPatrick Palka <ppalka@redhat.com>
Mon, 2 Feb 2026 20:14:20 +0000 (15:14 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 2 Feb 2026 20:14:20 +0000 (15:14 -0500)
Prevents uninitialized read bugs, and it's also just natural to assume
flags are initially cleared rather than uninitialized.

In passing rename the _M_end flag to _M_subexpr_end to make it distinct
from _Executor::_M_end.

libstdc++-v3/ChangeLog:

* include/bits/regex_executor.tcc (_ExecutorFrameBase):
Zero-initialize _M_byte0.
(_ExecutorFrameBase::_M_end): Rename to ...
(_ExecutorFrameBase::_M_subexpr_end): ... this.
(_Executor::_M_handle_subexpr_begin): Remove now redundant
clearing of _M_subexpr_end.
(_Executor::_M_handle_subexpr_end): Adjust after renaming.
(_Executor::_M_dfs) <case _S_fopcode_restore_cur_results>:
Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/include/bits/regex_executor.tcc

index 6c8deff2f21e9407e75a802fc8adf8a3fd87ae1c..19b5ad27df40f7b767da7b49a257e0ad85892b3c 100644 (file)
@@ -79,12 +79,12 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
 
     _ExecutorFrameOpcode _M_op;
     union {
-      unsigned char _M_byte0;
+      unsigned char _M_byte0 = 0;
       struct { // Used by restore_rep_count frame
        unsigned char _M_count : 2;
       };
       struct { // Used by restore_cur_results frame
-       unsigned char _M_end : 1;
+       unsigned char _M_subexpr_end : 1;
        unsigned char _M_matched : 1;
       };
     };
@@ -338,7 +338,6 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
       _M_frames.emplace_back(_S_fopcode_restore_cur_results,
                             static_cast<_StateIdT>(__state._M_subexpr),
                             __res.first);
-      _M_frames.back()._M_end = false;
       __res.first = _M_current;
       _M_frames.emplace_back(_S_fopcode_next, __state._M_next);
     }
@@ -353,7 +352,7 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
       _M_frames.emplace_back(_S_fopcode_restore_cur_results,
                             static_cast<_StateIdT>(__state._M_subexpr),
                             __res.second);
-      _M_frames.back()._M_end = true;
+      _M_frames.back()._M_subexpr_end = true;
       _M_frames.back()._M_matched = __res.matched;
       __res.second = _M_current;
       __res.matched = true;
@@ -670,7 +669,7 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2)
              break;
 
            case _S_fopcode_restore_cur_results:
-             if (!__frame._M_end)
+             if (!__frame._M_subexpr_end)
                _M_cur_results[__frame._M_state_id].first = __frame._M_pos;
              else
                {