当前位置:网站首页>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---ADC
- Example 001: the number combination has four numbers: 1, 2, 3, 4. How many three digits can be formed that are different from each other and have no duplicate numbers? How many are each?
- Bluebridge cup internet of things basic graphic tutorial - GPIO output control LD5 on and off
- 猜谜语啦(10)
- 轮子1:QCustomPlot初始化模板
- How apaas is applied in different organizational structures
- STM32 --- serial port communication
- Example 006: Fibonacci series
- Void* C is a carrier for realizing polymorphism
- Circleq of linked list
猜你喜欢

每日一题——输入一个日期,输出它是该年的第几天

Stm32--- systick timer

Summary of SIM card circuit knowledge

实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

MATLAB小技巧(28)模糊綜合評價

Detailed summary of FIO test hard disk performance parameters and examples (with source code)

How to write cover letter?

UE像素流,来颗“减肥药”吧!

Keil use details -- magic wand

Xrosstools tool installation for X-Series
随机推荐
PIP installation
UE pixel stream, come to a "diet pill"!
2020-05-21
【NOI模拟赛】汁树(树形DP)
Arduino+a4988 control stepper motor
STM32 tutorial triple ADC interleaved sampling
Working principle and type selection of common mode inductor
Sizeof (function name) =?
OC and OD gate circuit
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
Agile project management of project management
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
319. 灯泡开关
Xrosstools tool installation for X-Series
QEMU STM32 vscode debugging environment configuration
[three tier architecture and JDBC summary]
Is the security account given by Yixue school safe? Where can I open an account
STM32 --- GPIO configuration & GPIO related library functions
实例006:斐波那契数列
Infected Tree(树形dp)