From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:57:45 +0000 (+0200) Subject: [3.12] gh-120155: Add assertion to sre.c match_getindex() (GH-120402) (#120410) X-Git-Tag: v3.12.5~231 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab309343655a668863e6fcec9de4cfd428ba0392;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-120155: Add assertion to sre.c match_getindex() (GH-120402) (#120410) gh-120155: Add assertion to sre.c match_getindex() (GH-120402) Add an assertion to help static analyzers to detect that i*2 cannot overflow. (cherry picked from commit 42b25dd61ff3593795c4cc2ffe876ab766098b24) Co-authored-by: Victor Stinner --- diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c index 8ef35d0658c7..6d9843bb76d7 100644 --- a/Modules/_sre/sre.c +++ b/Modules/_sre/sre.c @@ -2167,6 +2167,8 @@ match_getindex(MatchObject* self, PyObject* index) return -1; } + // Check that i*2 cannot overflow to make static analyzers happy + assert(i <= SRE_MAXGROUPS); return i; }