当前位置:网站首页>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 ..
边栏推荐
- Use indent to format code
- Apaas platform of TOP10 abroad
- Chapter 18 using work queue manager (1)
- L298N module use
- 剑指 Offer 05. 替换空格
- Explore the authentication mechanism of StarUML
- Tailq of linked list
- 每日一题——替换空格
- 【NOI模拟赛】汁树(树形DP)
- Google sitemap files for rails Projects - Google sitemap files for rails projects
猜你喜欢

Classic application of MOS transistor circuit design (2) - switch circuit design

Explain task scheduling based on Cortex-M3 in detail (Part 1)

STM32---IIC

Circleq of linked list

Arduino operation stm32

猜谜语啦(142)

STM32 single chip microcomputer -- debug in keil5 cannot enter the main function

STM32 single chip microcomputer - external interrupt

Example 006: Fibonacci series

Keil use details -- magic wand
随机推荐
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
Anonymous structure in C language
STM32---IIC
Stm32--- systick timer
猜谜语啦(2)
99 multiplication table (C language)
Affected tree (tree DP)
Buildroot system for making raspberry pie cm3
319. 灯泡开关
C language data type replacement
Problem solving: interpreter error: no file or directory
Management and use of DokuWiki (supplementary)
Chapter 18 using work queue manager (1)
STM32 --- serial port communication
Several implementation schemes of anti reverse connection protection of positive and negative poles of power supply!
实例006:斐波那契数列
NTC thermistor application - temperature measurement
猜谜语啦(7)
Example 006: Fibonacci series
Esphone retrofits old fans