llvm/llvm-project

Create bugprone-printf-array check

Open

#40,511 建立於 2019年3月21日

在 GitHub 查看
 (9 留言) (0 反應) (0 負責人)C++ (10,782 fork)batch import
bugzillacheck-requestclang-tidygood first issue

倉庫指標

Star
 (26,378 star)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)

描述

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

貢獻者指南