llvm/llvm-project

Create bugprone-printf-array check

Open

#40.511 geöffnet am 21. März 2019

Auf GitHub ansehen
 (9 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C++ (10.782 Forks)batch import
bugzillacheck-requestclang-tidygood first issue

Repository-Metriken

Stars
 (26.378 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 1T 2h) (1.000 gemergte PRs in 30 T)

Beschreibung

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");
}

Contributor Guide