当前位置:网站首页>Member array and pointer in banyan loan C language structure
Member array and pointer in banyan loan C language structure
2022-07-27 03:34:00 【dongsijia】
Banyan loan implementation of the following Test function , The analysis will output the above results and what problems exist in the code .
1、 Pen test 1
void GetMemory(char* p)
{
p = (char*)malloc(100);
}
void Test(void)
{
char* str = NULL;
GetMemory(str);
strcpy(str, "hello world");
printf(str); // take str Send the first address of to printf function , feasible
Banyan loan analysis :
There are three problems in the above program :
First of all : Banyan loan in Test Call in function GetMemory Function time , The relay will be str Value , therefore GetMemory The parameters of the function p It's just str A temporary copy of , And str It doesn't matter , Will be developed dynamically 100 Bytes are passed to the pointer p Management is not right str Any impact ; And banyan loan even if the transmission is str The address of ,malloc Function application space may also fail ;
second : Banyan loan due to GetMemory Function does not make str Get space , therefore str Still NULL, Call at this time strcpy Function will cause program error ;
Third : Banyan loan code is not for dynamic development 100 Byte space free, Memory leaks can result ;
边栏推荐
猜你喜欢
随机推荐
MySQL:互联网公司常用分库分表方案汇总
[common search questions] 111
代码审查金字塔
768. 最多能完成排序的块 II 贪心
榕树贷款C语言结构体里的成员数组和指针
mysql出现不存在错误
Database usage security policy
复盘:图像有哪些基本属性?关于图像的知识你知道哪些?图像的参数有哪些
Comprehensive care analysis lyriq Ruige battery safety design
Practice of online problem feedback module (XV): realize the function of online updating feedback status
数据库使用安全策略
[flask] the server obtains the request header information of the client
Post responsibilities of safety officer and environmental protection officer
SAFE-ARC/WARNER电源维修XENON氙灯电源维修分析
【无标题】JDBC连接数据库读超时
Code practice when the queue reaches the maximum length
带你了解什么是 Web3.0
[机缘参悟-52]:交浅言深要因人而异
spark:地区广告点击量排行统计(小案例)
flask_restful中reqparse解析器继承









