当前位置:网站首页>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 ..
边栏推荐
- MATLAB小技巧(28)模糊综合评价
- STM32---ADC
- STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
- MySQL MHA high availability cluster
- Let's briefly talk about the chips commonly used in mobile phones - OVP chips
- Arrangement of some library files
- Bluebridge cup internet of things basic graphic tutorial - GPIO input key control LD5 on and off
- Working principle and type selection of common mode inductor
- Tailq of linked list
- 实例001:数字组合 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
猜你喜欢
实例009:暂停一秒输出
Charge pump boost principle - this article will give you a simple understanding
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
STM32 virtualization environment of QEMU
STM32 --- NVIC interrupt
319. 灯泡开关
猜谜语啦(142)
Lori remote control commissioning record
Arduino operation stm32
Typical low code apaas manufacturer cases
随机推荐
每日一题——输入一个日期,输出它是该年的第几天
实例007:copy 将一个列表的数据复制到另一个列表中。
猜谜语啦(142)
Stablq of linked list
Cmder of win artifact
Affected tree (tree DP)
How to write cover letter?
Classic application of MOS transistor circuit design (1) -iic bidirectional level shift
Keil use details -- magic wand
实例010:给人看的时间
Array integration initialization (C language)
剑指 Offer 06. 从尾到头打印链表
Arduino+a4988 control stepper motor
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
Working principle and type selection of common mode inductor
轮子1:QCustomPlot初始化模板
Google sitemap files for rails Projects - Google sitemap files for rails projects
STM32---IIC
Brief discussion on Buck buck circuit
Sizeof (function name) =?