brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 42e8dd9 Raw
45 lines · plain
1.. title:: clang-tidy - android-comparison-in-temp-failure-retry2 3android-comparison-in-temp-failure-retry4========================================5 6Diagnoses comparisons that appear to be incorrectly placed in the argument to7the ``TEMP_FAILURE_RETRY`` macro. Having such a use is incorrect in the vast8majority of cases, and will often silently defeat the purpose of the9``TEMP_FAILURE_RETRY`` macro.10 11For context, ``TEMP_FAILURE_RETRY`` is `a convenience macro12<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 syscall14until it either succeeds, or fails for reasons other than being interrupted.15 16Example buggy usage looks like:17 18.. code-block:: c19 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 result26*of the comparison* is ``-1``, and retry if so.27 28If you encounter this, the fix is simple: lift the comparison out of the29``TEMP_FAILURE_RETRY`` argument, like so:30 31.. code-block:: c32 33  char cs[1];34  while (TEMP_FAILURE_RETRY(read(STDIN_FILENO, cs, sizeof(cs))) != 0) {35    // Do something with cs.36  }37 38Options39-------40 41.. option:: RetryMacros42 43   A comma-separated list of the names of retry macros to be checked.44   Default is `TEMP_FAILURE_RETRY`.45