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