Title: [260860] trunk/Tools
Revision
260860
Author
[email protected]
Date
2020-04-28 19:59:52 -0700 (Tue, 28 Apr 2020)

Log Message

check-webkit-style should suggest CheckedSize for Checked<size_t, RecordOverflow>
<https://webkit.org/b/211158>

Reviewed by Darin Adler.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_wtf_checked_size): Add checker.
(check_style): Call check_wtf_checked_size() to check.
(CppChecker): Add 'runtime/wtf_checked_size'.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_wtf_checked_size): Add tests.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (260859 => 260860)


--- trunk/Tools/ChangeLog	2020-04-29 00:26:31 UTC (rev 260859)
+++ trunk/Tools/ChangeLog	2020-04-29 02:59:52 UTC (rev 260860)
@@ -1,3 +1,17 @@
+2020-04-28  David Kilzer  <[email protected]>
+
+        check-webkit-style should suggest CheckedSize for Checked<size_t, RecordOverflow>
+        <https://webkit.org/b/211158>
+
+        Reviewed by Darin Adler.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_wtf_checked_size): Add checker.
+        (check_style): Call check_wtf_checked_size() to check.
+        (CppChecker): Add 'runtime/wtf_checked_size'.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_wtf_checked_size): Add tests.
+
 2020-04-28  Lauro Moura  <[email protected]>
 
         [GTK] update-webkitgtk-libs: TypeError: cannot use a string pattern on a bytes-like object

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (260859 => 260860)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2020-04-29 00:26:31 UTC (rev 260859)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2020-04-29 02:59:52 UTC (rev 260860)
@@ -2473,6 +2473,30 @@
           % (max_min_macro_lower, max_min_macro_lower, max_min_macro))
 
 
+def check_wtf_checked_size(clean_lines, line_number, file_state, error):
+    """Looks for use of 'Checked<size_t, RecordOverflow>' which should be replaced with 'CheckedSize'.
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
+      error: The function to call with any errors found.
+    """
+
+    if file_state.is_c_or_objective_c():
+        return
+
+    line = clean_lines.elided[line_number]
+
+    using_checked_size_record_overflow = search(r'\bChecked\s*<\s*size_t,\s*RecordOverflow\s*>\s*(\b|\()', line)
+    if not using_checked_size_record_overflow:
+        return
+
+    error(line_number, 'runtime/wtf_checked_size', 5,
+          "Use 'CheckedSize' instead of 'Checked<size_t, RecordOverflow>'.")
+
+
 def check_wtf_move(clean_lines, line_number, file_state, error):
     """Looks for use of 'std::move()' which should be replaced with 'WTFMove()'.
 
@@ -3143,6 +3167,7 @@
     check_using_std(clean_lines, line_number, file_state, error)
     check_using_namespace(clean_lines, line_number, file_extension, error)
     check_max_min_macros(clean_lines, line_number, file_state, error)
+    check_wtf_checked_size(clean_lines, line_number, file_state, error)
     check_wtf_move(clean_lines, line_number, file_state, error)
     check_wtf_optional(clean_lines, line_number, file_state, error)
     check_wtf_make_unique(clean_lines, line_number, file_state, error)
@@ -4325,6 +4350,7 @@
         'runtime/threadsafe_fn',
         'runtime/unsigned',
         'runtime/virtual',
+        'runtime/wtf_checked_size',
         'runtime/wtf_optional',
         'runtime/wtf_make_unique',
         'runtime/wtf_move',

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (260859 => 260860)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2020-04-29 00:26:31 UTC (rev 260859)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2020-04-29 02:59:52 UTC (rev 260860)
@@ -5432,6 +5432,31 @@
             '  [runtime/max_min_macros] [4]',
             'foo.h')
 
+    def test_wtf_checked_size(self):
+        self.assert_lint(
+            'CheckedSize totalSize = barSize;\n'
+            'totalSize += bazSize;',
+            '',
+            'foo.cpp')
+
+        self.assert_lint(
+            'auto totalSize = CheckedSize(barSize) + bazSize;',
+            '',
+            'foo.cpp')
+
+        self.assert_lint(
+            'Checked<size_t, RecordOverflow> totalSize = barSize;\n'
+            'totalSize += bazSize;',
+            "Use 'CheckedSize' instead of 'Checked<size_t, RecordOverflow>'."
+            "  [runtime/wtf_checked_size] [5]",
+            'foo.cpp')
+
+        self.assert_lint(
+            'auto totalSize = Checked<size_t, RecordOverflow>(barSize) + bazSize;',
+            "Use 'CheckedSize' instead of 'Checked<size_t, RecordOverflow>'."
+            "  [runtime/wtf_checked_size] [5]",
+            'foo.cpp')
+
     def test_wtf_make_unique(self):
         self.assert_lint(
              'std::unique_ptr<Foo> foo = WTF::makeUnique<Foo>();',
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to