1 .. title:: clang-tidy - android-comparison-in-temp-failure-retry
3 android-comparison-in-temp-failure-retry
4 ========================================
6 Diagnoses comparisons that appear to be incorrectly placed in the argument to
7 the ``TEMP_FAILURE_RETRY`` macro. Having such a use is incorrect in the vast
8 majority of cases, and will often silently defeat the purpose of the
9 ``TEMP_FAILURE_RETRY`` macro.
11 For context, ``TEMP_FAILURE_RETRY`` is `a convenience macro
12 <https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html>`_
13 provided by both glibc and Bionic. Its purpose is to repeatedly run a syscall
14 until it either succeeds, or fails for reasons other than being interrupted.
16 Example buggy usage looks like:
21 while (TEMP_FAILURE_RETRY(read(STDIN_FILENO, cs, sizeof(cs)) != 0)) {
22 // Do something with cs.
25 Because TEMP_FAILURE_RETRY will check for whether the result *of the comparison*
26 is ``-1``, and retry if so.
28 If you encounter this, the fix is simple: lift the comparison out of the
29 ``TEMP_FAILURE_RETRY`` argument, like so:
34 while (TEMP_FAILURE_RETRY(read(STDIN_FILENO, cs, sizeof(cs))) != 0) {
35 // Do something with cs.
41 .. option:: RetryMacros
43 A comma-separated list of the names of retry macros to be checked.