brintos

brintos / llvm-project-archived public Read only

0
0
Text · 772 B · 8e0191a Raw
26 lines · plain
1.. title:: clang-tidy - bugprone-misplaced-pointer-arithmetic-in-alloc2 3bugprone-misplaced-pointer-arithmetic-in-alloc4===============================================5 6Finds cases where an integer expression is added to or subtracted from the7result of a memory allocation function (``malloc()``, ``calloc()``,8``realloc()``, ``alloca()``) instead of its argument. The check detects error9cases even if one of these functions is called by a constant function pointer.10 11Example code:12 13.. code-block:: c14 15  void bad_malloc(int n) {16    char *p = (char*) malloc(n) + 10;17  }18 19 20The suggested fix is to add the integer expression to the argument of21``malloc`` and not to its result. In the example above the fix would be22 23.. code-block:: c24 25  char *p = (char*) malloc(n + 10);26