]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-120155: Add assertion to sre.c match_getindex() (GH-120402) (#120410)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 12 Jun 2024 13:57:45 +0000 (15:57 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jun 2024 13:57:45 +0000 (13:57 +0000)
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 <vstinner@python.org>
Modules/_sre/sre.c

index 8ef35d0658c703e77d2ebd79c2a4aff6039c990b..6d9843bb76d7918f6e23d4e521530affc4ea3d61 100644 (file)
@@ -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;
 }