]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111178: Skip undefined behavior checks in _PyPegen_lookahead() (#131714)
authorVictor Stinner <vstinner@python.org>
Thu, 27 Mar 2025 09:03:58 +0000 (10:03 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Mar 2025 09:03:58 +0000 (10:03 +0100)
For example, expression_rule() return type is 'expr_ty', whereas
_PyPegen_lookahead() uses 'void*'.

Parser/pegen.c

index 592269ead31e397ff0e440c55fdae8db7fe219a2..75fdd467e55045fb96934b287a2e312a6707606f 100644 (file)
@@ -406,11 +406,14 @@ _PyPegen_lookahead_with_int(int positive, Token *(func)(Parser *, int), Parser *
     return (res != NULL) == positive;
 }
 
-int
+// gh-111178: Use _Py_NO_SANITIZE_UNDEFINED to disable sanitizer checks on
+// undefined behavior (UBsan) in this function, rather than changing 'func'
+// callback API.
+int _Py_NO_SANITIZE_UNDEFINED
 _PyPegen_lookahead(int positive, void *(func)(Parser *), Parser *p)
 {
     int mark = p->mark;
-    void *res = (void*)func(p);
+    void *res = func(p);
     p->mark = mark;
     return (res != NULL) == positive;
 }