您现在的位置是:首页 > 文章详情

Git 源码禁止使用 C 标准库中容易被错用的函数

日期:2019-08-26点击:444

Git 项目的源码禁止开发者使用 C 标准库中的某些函数,原因是这些函数太容易被误用,就算使用得当也很容易出问题。因此 Git 的源码增加了一个 banned.h 的头函数,一旦你使用了这些被禁用的函数,将在编译时报错。

这些函数包括:

 #ifndef BANNED_H #define 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. */ #define BANNED(func) sorry_##func##_is_a_banned_function #undef strcpy #define strcpy(x,y) BANNED(strcpy) #undef strcat #define strcat(x,y) BANNED(strcat) #undef strncpy #define strncpy(x,y,n) BANNED(strncpy) #undef strncat #define strncat(x,y,n) BANNED(strncat) #undef sprintf #undef vsprintf #ifdef HAVE_VARIADIC_MACROS #define sprintf(...) BANNED(sprintf) #define vsprintf(...) BANNED(vsprintf) #else #define sprintf(buf,fmt,arg) BANNED(sprintf) #define vsprintf(buf,fmt,arg) BANNED(sprintf) #endif #endif /* BANNED_H */

banned.h 源码  https://gitee.com/mirrors/git/blob/master/banned.h

原文链接:https://www.oschina.net/news/109364/git-source-banned-c-stdlib
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章