当前位置:网站首页>Reasons for the insecurity of C language standard function scanf
Reasons for the insecurity of C language standard function scanf
2022-07-05 08:33:00 【Bright moon and clear wind - continuous improvement】
scanf It's a standard. C Standard library functions for languages ;
scanf_s Is Microsoft's , Than scanf Added a parameter , The number of characters to be input must be specified ;
eg:
char buf[5]={0};
scanf("%s",buf);// If input 1234567890, be 5 The following characters will also be read , It may be written to the location of other variables , Cause procedure
// abnormal , stay VS2019 Next test , Program crash . If input 12, It's normal
char buf[5]={0};
scanf_s("%s",buf,4);// Only the number of space characters can be stored -1 Characters Because the last space to store \0
// stay vs2019 Next test , If input ≤4 Characters , Everything is all right , If input 5 Characters or more , The program doesn't crash , however buf No data in , The reason should be 4 Within characters ( contain ) No carriage return received , So it is not written into buf in ..
边栏推荐
- STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
- Stablq of linked list
- Tailq of linked list
- 实例006:斐波那契数列
- 猜谜语啦(142)
- QEMU demo makefile analysis
- UE pixel stream, come to a "diet pill"!
- MATLAB小技巧(28)模糊综合评价
- Xrosstools tool installation for X-Series
- 实例002:“个税计算” 企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.
猜你喜欢
leetcode - 445. Add two numbers II
On boost circuit
OC and OD gate circuit
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
Low code platform | apaas platform construction analysis
DokuWiki deployment notes
Charge pump boost principle - this article will give you a simple understanding
猜谜语啦(142)
STM32 --- NVIC interrupt
实例006:斐波那契数列
随机推荐
Talk about the function of magnetic beads in circuits
99 multiplication table (C language)
关于线性稳压器的五个设计细节
【三层架构及JDBC总结】
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
How can fresh students write resumes to attract HR and interviewers
UE pixel stream, come to a "diet pill"!
關於線性穩壓器的五個設計細節
Esphone retrofits old fans
STM32 single chip microcomputer -- volatile keyword
Count the number of inputs (C language)
DCDC circuit - function of bootstrap capacitor
Summary of SIM card circuit knowledge
STM32---ADC
287. 寻找重复数-快慢指针
Charge pump boost principle - this article will give you a simple understanding
Stm32--- systick timer
MySQL之MHA高可用集群
STM32 tutorial triple ADC interleaved sampling
Speech recognition learning summary