]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-120155: Add assertion to sre.c match_getindex() (GH-120402) (#120409)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 12 Jun 2024 14:07:36 +0000 (16:07 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Jun 2024 14:07:36 +0000 (14:07 +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 e33034086481c23174cbca8dc797cab8cf3f0e64..0c656b47991c2f1c9881f25540e3a5513149bac5 100644 (file)
@@ -2217,6 +2217,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;
 }