Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: d93063803637c13838d638be397f263044d67e75
      
https://github.com/WebKit/WebKit/commit/d93063803637c13838d638be397f263044d67e75
  Author: David Kilzer <[email protected]>
  Date:   2026-02-09 (Mon, 09 Feb 2026)

  Changed paths:
    M Tools/Scripts/webkitpy/style/checkers/cpp.py
    M Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

  Log Message:
  -----------
  [check-webkit-style] Fix false positive in safercpp/protected_getter_for_init 
checker
<https://bugs.webkit.org/show_bug.cgi?id=307347>
<rdar://169975626>

Reviewed by Chris Dumez.

The checker was incorrectly flagging code where `protect()`, `protectedFoo()`,
or `checkedFoo()` was used as an argument to another function, not as the
direct initializer.  For example, 
`viewportDocumentForFrame(protect(mainFrame()))`
was flagged even though `protect()` is just an argument, not the initializer.

The original regex patterns included `(` and `)` in their character classes,
allowing them to match through function call boundaries.

For `protectedFoo()` and `checkedFoo()` checks, add negative lookbehind
`(?<!\()` before `protected` and `checked` patterns to prevent matching
when immediately preceded by `(`:

  Before: r'= [a-zA-Z0-9_.(),\s\->]*protected[a-zA-Z0-9]+\(\)(;|\))(?!;)'
  After:  r'= [a-zA-Z0-9_.(),\s\->]*(?<!\()protected[a-zA-Z0-9]+\(\)(;|\))(?!;)'

For `protect()` check, change character class from `[a-zA-Z0-9_.(),\s\->]*`
to `[a-zA-Z0-9_<>,\s]*` to remove `()` and prevent matching through nested
function calls, while adding `<>` to support template parameters like
`RefPtr<Document>`:

  Before: r'=\s*[a-zA-Z0-9_.(),\s\->]*protect\(...
  After:  r'=\s*[a-zA-Z0-9_<>,\s]*protect\(...

* Tools/Scripts/webkitpy/style/checkers/cpp.py:
(check_safer_cpp):
* Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_safer_cpp):

Canonical link: https://commits.webkit.org/307125@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to