From 52ca09f489c6f546982585096841c60561589240 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 25 Mar 2025 12:58:12 +0100 Subject: [PATCH] gh-111178: Skip undefined behavior checks in _PyPegen_lookahead() For example, expression_rule() return type is 'expr_ty', whereas _PyPegen_lookahead() uses 'void*'. --- Parser/pegen.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Parser/pegen.c b/Parser/pegen.c index 87a9ba02274d9f..94d83786164b1e 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -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; }