llvm/llvm-project

Create bugprone-printf-array check

Open

#40 511 ouverte le 21 mars 2019

Voir sur GitHub
 (9 commentaires) (0 réactions) (0 assignés)C++ (10 782 forks)batch import
bugzillacheck-requestclang-tidygood first issue

Métriques du dépôt

Stars
 (26 378 stars)
Métriques de merge PR
 (Merge moyen 1j 2h) (1 000 PRs mergées en 30 j)

Description

Bugzilla Link 41166
Version unspecified
OS All

Extended Description

It's a common idiom to have a fixed-size buffer of characters allocated on the stack and then to printf into the buffer. Create a check that recommends that the counted versions of functions are used, e.g. prefer snprintf over sprintf.

Example:

void f()
{
  char buff[80];
  sprintf(buff, "Hello, %s!\n", "world");
}

Becomes:

void f()
{
  char buff[80];
  snprintf(buff, sizeof(buff), "Hello, %s!\n", "world");
}

Guide contributeur