当前位置:网站首页>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 --- configuration of external interrupt
- 猜谜语啦(10)
- Arduino+a4988 control stepper motor
- Weidongshan Internet of things learning lesson 1
- Example 003: a complete square is an integer. It is a complete square after adding 100, and it is a complete square after adding 168. What is the number?
- Stablq of linked list
- Sword finger offer 06 Print linked list from end to end
- [three tier architecture]
- 287. 寻找重复数-快慢指针
- Google sitemap files for rails Projects - Google sitemap files for rails projects
猜你喜欢
Meizu Bluetooth remote control temperature and humidity access homeassistant
MATLAB skills (28) Fuzzy Comprehensive Evaluation
More than 90% of hardware engineers will encounter problems when MOS tubes are burned out!
Take you to understand the working principle of lithium battery protection board
OC and OD gate circuit
Example 008: 99 multiplication table
猜谜语啦(3)
Circleq of linked list
猜谜语啦(142)
Explain task scheduling based on Cortex-M3 in detail (Part 2)
随机推荐
Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
Example 002: the bonus paid by the "individual income tax calculation" enterprise is based on the profit commission. When the profit (I) is less than or equal to 100000 yuan, the bonus can be increase
MATLAB小技巧(28)模糊综合评价
猜谜语啦(6)
Affected tree (tree DP)
Problem solving: interpreter error: no file or directory
287. 寻找重复数-快慢指针
How to write cover letter?
NTC thermistor application - temperature measurement
99 multiplication table (C language)
Explore the authentication mechanism of StarUML
Esphone retrofits old fans
Typical low code apaas manufacturer cases
Talk about the function of magnetic beads in circuits
STM32 single chip microcomputer - bit band operation
Example 004: for the day of the day, enter a day of a month of a year to judge the day of the year?
696. 计数二进制子串
Why is 1900 not a leap year
L298N module use
2022.7.4-----leetcode. one thousand and two hundred