llvm/llvm-project

Create bugprone-printf-array check

Open

#40.511 aperta il 21 mar 2019

Vedi su GitHub
 (9 commenti) (0 reazioni) (0 assegnatari)C++ (10.782 fork)batch import
bugzillacheck-requestclang-tidygood first issue

Metriche repository

Star
 (26.378 star)
Metriche merge PR
 (Merge medio 1g 2h) (1000 PR mergiate in 30 g)

Descrizione

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

Guida contributor