pragma GCC poison GCC编译屏蔽不安全函数

收集不安全的c函数,使用预编译属性禁止这些函数在项目源码中使用

1.poison.h

#ifndef __POISON_H_
#define __POISON_H_

#ifdef __cplusplus
extern "C"{
#endif /* __cplusplus */


/*****************************************************************************************************************************/
/* 标准输入输出被禁用函数列表-注释中为对应安全替代函数 */
#pragma GCC poison	gets						/* char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)*/




/*****************************************************************************************************************************/
/* 字符串处理-注释中为对应安全替代函数 */
#pragma GCC poison	strtok						/* char *__strtok_r (char *__restrict __s,
													 const char *__restrict __delim,
													 char **__restrict __save_ptr) */ 													 
#pragma GCC poison	strcpy						/* char *strncpy (char *__restrict __dest,
													const char *__restrict __src, size_t __n) */
#pragma GCC poison 	strcat						/* char *strncat (char *__restrict __dest, const char *__restrict __src,
													size_t __n) */						
#pragma GCC poison 	sprintf						/* int snprintf (char *__restrict __s, size_t __maxlen,
													const char *__restrict __format, ...) */												
#pragma GCC poison 	vsprintf					/* int vsnprintf (char *__restrict __s, size_t __maxlen,
													const char *__restrict __format, _G_va_list __arg)*/									
													
																					
/*****************************************************************************************************************************/													
/* 时间系统被禁用函数列表-注释中为对应安全替代函数 */
#pragma GCC poison 	gmtime 						/*	struct tm *gmtime_r(const time_t *timep, struct tm *result); */
#pragma GCC poison 	ctime						/*	char *ctime_r(const time_t *timep, char *buf); */
#pragma GCC poison 	asctime						/*	char *asctime_r(const struct tm *tm, char *buf); */
#pragma GCC poison	localtime					/*	struct tm *localtime_r(const time_t *timep, struct tm *result) */

/* 待确定修改项 */  
#pragma GCC poison	localtime_r 				/* 	int bsLocalTime(time_t *pTimeT, struct tm *pTm)	*/



/*****************************************************************************************************************************/
/* 网络接口被禁用函数列表-注释中为对应安全替代函数 */
#pragma GCC poison	gethostbyaddr				/* 	int gethostbyaddr_r (const void *__restrict __addr, __socklen_t __len,
													int __type,
													struct hostent *__restrict __result_buf,
													char *__restrict __buf, size_t __buflen,
													struct hostent **__restrict __result,
													int *__restrict __h_errnop);	*/
#pragma GCC poison	gethostbyname				/* 	int gethostbyname_r (const char *__restrict __name,
													struct hostent *__restrict __result_buf,
													char *__restrict __buf, size_t __buflen,
													struct hostent **__restrict __result,
													int *__restrict __h_errnop);	*/
//#pragma GCC poison	inet_ntoa					/* 	暂无	*/



/*****************************************************************************************************************************/
/* 自定义函数-注释中为对应安全替代函数 */



#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif










  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值