brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · e38b298 Raw
32 lines · plain
1.. title:: clang-tidy - bugprone-unchecked-string-to-number-conversion2 3bugprone-unchecked-string-to-number-conversion4==============================================5 6This check flags calls to string-to-number conversion functions that do not7verify the validity of the conversion, such as ``atoi()`` or ``scanf()``. It8does not flag calls to ``strtol()``, or other, related conversion functions9that do perform better error checking.10 11.. code-block:: c12 13  #include <stdlib.h>14 15  void func(const char *buff) {16    int si;17 18    if (buff) {19      si = atoi(buff); /* 'atoi' used to convert a string to an integer, but function will20                           not report conversion errors; consider using 'strtol' instead. */21    } else {22      /* Handle error */23    }24  }25 26References27----------28 29This check corresponds to the CERT C Coding Standard rule30`ERR34-C. Detect errors when converting a string to a number31<https://www.securecoding.cert.org/confluence/display/c/ERR34-C.+Detect+errors+when+converting+a+string+to+a+number>`_.32