comparison clang/docs/analyzer/checkers.rst @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
comparison
equal deleted inserted replaced
172:9fbae9c8bf63 173:0572611fdcc8
1372 zx_handle_close(sa); 1372 zx_handle_close(sa);
1373 use(sb); // Warn: Potential leak of handle 1373 use(sb); // Warn: Potential leak of handle
1374 zx_handle_close(sb); 1374 zx_handle_close(sb);
1375 } 1375 }
1376 1376
1377 WebKit
1378 ^^^^^^
1379
1380 WebKit is an open-source web browser engine available for macOS, iOS and Linux.
1381 This section describes checkers that can find issues in WebKit codebase.
1382
1383 Most of the checkers focus on memory management for which WebKit uses custom implementation of reference counted smartpointers.
1384 Checker are formulated in terms related to ref-counting:
1385 * *Ref-counted type* is either ``Ref<T>`` or ``RefPtr<T>``.
1386 * *Ref-countable type* is any type that implements ``ref()`` and ``deref()`` methods as ``RefPtr<>`` is a template (i. e. relies on duck typing).
1387 * *Uncounted type* is ref-countable but not ref-counted type.
1388
1389 .. _webkit-RefCntblBaseVirtualDtor:
1390
1391 webkit.RefCntblBaseVirtualDtor
1392 """"""""""""""""""""""""""""""""""""
1393 All uncounted types used as base classes must have a virtual destructor.
1394
1395 Ref-counted types hold their ref-countable data by a raw pointer and allow implicit upcasting from ref-counted pointer to derived type to ref-counted pointer to base type. This might lead to an object of (dynamic) derived type being deleted via pointer to the base class type which C++ standard defines as UB in case the base class doesn't have virtual destructor ``[expr.delete]``.
1396
1397 .. code-block:: cpp
1398
1399 struct RefCntblBase {
1400 void ref() {}
1401 void deref() {}
1402 };
1403
1404 struct Derived : RefCntblBase { }; // warn
1377 1405
1378 .. _alpha-checkers: 1406 .. _alpha-checkers:
1379 1407
1380 Experimental Checkers 1408 Experimental Checkers
1381 --------------------- 1409 ---------------------
1927 reminderCount]; 1955 reminderCount];
1928 } 1956 }
1929 1957
1930 alpha.security 1958 alpha.security
1931 ^^^^^^^^^^^^^^ 1959 ^^^^^^^^^^^^^^
1960
1961
1962 alpha.security.cert
1963 ^^^^^^^^^^^^^^^^^^^
1964
1965 SEI CERT checkers which tries to find errors based on their `C coding rules <https://wiki.sei.cmu.edu/confluence/display/c/2+Rules>`_.
1966
1967 .. _alpha-security-cert-pos-checkers:
1968
1969 alpha.security.cert.pos
1970 ^^^^^^^^^^^^^^^^^^^^^^^
1971
1972 SEI CERT checkers of `POSIX C coding rules <https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152405>`_.
1973
1974 .. _alpha-security-cert-pos-34c:
1975
1976 alpha.security.cert.pos.34c
1977 """""""""""""""""""""""""""
1978 Finds calls to the ``putenv`` function which pass a pointer to an automatic variable as the argument.
1979
1980 .. code-block:: c
1981
1982 int func(const char *var) {
1983 char env[1024];
1984 int retval = snprintf(env, sizeof(env),"TEST=%s", var);
1985 if (retval < 0 || (size_t)retval >= sizeof(env)) {
1986 /* Handle error */
1987 }
1988
1989 return putenv(env); // putenv function should not be called with auto variables
1990 }
1991
1932 .. _alpha-security-ArrayBound: 1992 .. _alpha-security-ArrayBound:
1933 1993
1934 alpha.security.ArrayBound (C) 1994 alpha.security.ArrayBound (C)
1935 """"""""""""""""""""""""""""" 1995 """""""""""""""""""""""""""""
1936 Warn about buffer overflows (older checker). 1996 Warn about buffer overflows (older checker).
2165 .. _alpha-unix-SimpleStream: 2225 .. _alpha-unix-SimpleStream:
2166 2226
2167 alpha.unix.SimpleStream (C) 2227 alpha.unix.SimpleStream (C)
2168 """"""""""""""""""""""""""" 2228 """""""""""""""""""""""""""
2169 Check for misuses of stream APIs. Check for misuses of stream APIs: ``fopen, fclose`` 2229 Check for misuses of stream APIs. Check for misuses of stream APIs: ``fopen, fclose``
2170 (demo checker, the subject of the demo (`Slides <http://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf>`_ , 2230 (demo checker, the subject of the demo (`Slides <https://llvm.org/devmtg/2012-11/Zaks-Rose-Checker24Hours.pdf>`_ ,
2171 `Video <https://youtu.be/kdxlsP5QVPw>`_) by Anna Zaks and Jordan Rose presented at the 2231 `Video <https://youtu.be/kdxlsP5QVPw>`_) by Anna Zaks and Jordan Rose presented at the
2172 `2012 LLVM Developers' Meeting <http://llvm.org/devmtg/2012-11/>`_). 2232 `2012 LLVM Developers' Meeting <https://llvm.org/devmtg/2012-11/>`_).
2173 2233
2174 .. code-block:: c 2234 .. code-block:: c
2175 2235
2176 void test() { 2236 void test() {
2177 FILE *F = fopen("myfile.txt", "w"); 2237 FILE *F = fopen("myfile.txt", "w");