Git 裡面禁用的函式...

Hacker News Daily 上看到 Git 裡面禁用的函式 (透過 .h 在編譯階段就擋下來):「banned.h」,在開頭有說明原因:

/*
 * This header lists functions that have been banned from our code base,
 * because they're too easy to misuse (and even if used correctly,
 * complicate audits). Including this header turns them into compile-time
 * errors.
 */

就算用的正確也增加了稽核的難度... 這些被禁用的函式包括了:

  • strcpy()
  • strcat()
  • strncpy()
  • strncat()
  • sprintf()
  • vsprintf()

所以應該是用 strlcpy()strlcat() 這些函式來處理字串,另外用 snprintf()vsnprintf() 來處理格式...

Leave a Reply

Your email address will not be published.