You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For all cast operations (C-style casts, static_cast, reinterpret_cast, dynamic_cast), if the source type a `Base*` and the destination type is `Derived*`, where `Derived` inherits from `Base`, the static analyzer should signal an error.
3454
+
3455
+
This applies to:
3456
+
3457
+
- C structs, C++ structs and classes, and Objective-C classes and protocols.
3458
+
- Pointers and references.
3459
+
- Inside template instantiations and macro expansions that are visible to the compiler.
3460
+
3461
+
For types like this, instead of using built in casts, the programmer will use helper functions that internally perform the appropriate type check and disable static analysis.
3462
+
3463
+
alpha.webkit.NoUncheckedPtrMemberChecker
3464
+
""""""""""""""""""""""""""""""""""""""""
3465
+
Raw pointers and references to an object which supports CheckedPtr or CheckedRef can't be used as class members. Only CheckedPtr, CheckedRef, RefPtr, or Ref are allowed.
3466
+
3467
+
.. code-block:: cpp
3468
+
3469
+
struct CheckableObj {
3470
+
void incrementCheckedPtrCount() {}
3471
+
void decrementCheckedPtrCount() {}
3472
+
};
3473
+
3474
+
struct Foo {
3475
+
CheckableObj* ptr; // warn
3476
+
CheckableObj& ptr; // warn
3477
+
// ...
3478
+
};
3479
+
3480
+
See `WebKit Guidelines for Safer C++ Programming <https://github.com/WebKit/WebKit/wiki/Safer-CPP-Guidelines>`_ for details.
3481
+
3436
3482
.. _alpha-webkit-UncountedCallArgsChecker:
3437
3483
3438
3484
alpha.webkit.UncountedCallArgsChecker
@@ -3522,6 +3568,12 @@ We also define a set of safe transformations which if passed a safe value as an
3522
3568
- casts
3523
3569
- unary operators like ``&`` or ``*``
3524
3570
3571
+
alpha.webkit.UncheckedCallArgsChecker
3572
+
"""""""""""""""""""""""""""""""""""""
3573
+
The goal of this rule is to make sure that lifetime of any dynamically allocated CheckedPtr capable object passed as a call argument keeps its memory region past the end of the call. This applies to call to any function, method, lambda, function pointer or functor. CheckedPtr capable objects aren't supposed to be allocated on stack so we check arguments for parameters of raw pointers and references to unchecked types.
3574
+
3575
+
The rules of when to use and not to use CheckedPtr / CheckedRef are same as alpha.webkit.UncountedCallArgsChecker for ref-counted objects.
3576
+
3525
3577
alpha.webkit.UncountedLocalVarsChecker
3526
3578
""""""""""""""""""""""""""""""""""""""
3527
3579
The goal of this rule is to make sure that any uncounted local variable is backed by a ref-counted object with lifetime that is strictly larger than the scope of the uncounted local variable. To be on the safe side we require the scope of an uncounted variable to be embedded in the scope of ref-counted object that backs it.
@@ -3546,7 +3598,7 @@ These are examples of cases that we consider safe:
3546
3598
RefCountable* uncounted = this; // ok
3547
3599
}
3548
3600
3549
-
Here are some examples of situations that we warn about as they *might* be potentially unsafe. The logic is that either we're able to guarantee that an argument is safe or it's considered if not a bug then bug-prone.
3601
+
Here are some examples of situations that we warn about as they *might* be potentially unsafe. The logic is that either we're able to guarantee that a local variable is safe or it's considered unsafe.
3550
3602
3551
3603
.. code-block:: cpp
3552
3604
@@ -3565,11 +3617,48 @@ Here are some examples of situations that we warn about as they *might* be poten
3565
3617
RefCountable* uncounted = counted.get(); // warn
3566
3618
}
3567
3619
3568
-
We don't warn about these cases - we don't consider them necessarily safe but since they are very common and usually safe we'd introduce a lot of false positives otherwise:
3569
-
- variable defined in condition part of an ```if``` statement
3570
-
- variable defined in init statement condition of a ```for``` statement
3620
+
alpha.webkit.UncheckedLocalVarsChecker
3621
+
""""""""""""""""""""""""""""""""""""""
3622
+
The goal of this rule is to make sure that any unchecked local variable is backed by a CheckedPtr or CheckedRef with lifetime that is strictly larger than the scope of the unchecked local variable. To be on the safe side we require the scope of an unchecked variable to be embedded in the scope of CheckedPtr/CheckRef object that backs it.
3623
+
3624
+
These are examples of cases that we consider safe:
3625
+
3626
+
.. code-block:: cpp
3627
+
3628
+
void foo1() {
3629
+
CheckedPtr<RefCountable> counted;
3630
+
// The scope of uncounted is EMBEDDED in the scope of counted.
RefCountable* uncounted = counted_param.get(); // ok
3638
+
}
3639
+
3640
+
void FooClass::foo_method() {
3641
+
RefCountable* uncounted = this; // ok
3642
+
}
3643
+
3644
+
Here are some examples of situations that we warn about as they *might* be potentially unsafe. The logic is that either we're able to guarantee that a local variable is safe or it's considered unsafe.
3571
3645
3572
-
For the time being we also don't warn about uninitialized uncounted local variables.
3646
+
.. code-block:: cpp
3647
+
3648
+
void foo1() {
3649
+
RefCountable* uncounted = new RefCountable; // warn
0 commit comments