当前位置:网站首页>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 ..
边栏推荐
- MySQL MHA high availability cluster
- 關於線性穩壓器的五個設計細節
- 猜谜语啦(10)
- Daily question - input a date and output the day of the year
- Several problems to be considered and solved in the design of multi tenant architecture
- Arduino burning program and Arduino burning bootloader
- 每日一题——替换空格
- STM32 virtualization environment of QEMU
- One question per day - replace spaces
- 猜谜语啦(7)
猜你喜欢
UE像素流,来颗“减肥药”吧!
STM32 --- serial port communication
猜谜语啦(4)
Stablq of linked list
猜谜语啦(10)
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
STM32 single chip microcomputer -- debug in keil5 cannot enter the main function
leetcode - 445. 两数相加 II
Apaas platform of TOP10 abroad
Classic application of MOS transistor circuit design (2) - switch circuit design
随机推荐
Arduino burning program and Arduino burning bootloader
实例005:三数排序 输入三个整数x,y,z,请把这三个数由小到大输出。
如何写Cover Letter?
Sword finger offer 05 Replace spaces
亿学学堂给的证券账户安不安全?哪里可以开户
Arduino+a4988 control stepper motor
实例003:完全平方数 一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
猜谜语啦(3)
[nas1] (2021cvpr) attentivenas: improving neural architecture search via attentive sampling (unfinished)
Detailed summary of FIO test hard disk performance parameters and examples (with source code)
Bluebridge cup internet of things competition basic graphic tutorial - clock selection
MySQL之MHA高可用集群
Sword finger offer 06 Print linked list from end to end
QEMU demo makefile analysis
Buildroot system for making raspberry pie cm3
[NAS1](2021CVPR)AttentiveNAS: Improving Neural Architecture Search via Attentive Sampling (未完)
Esp8266 interrupt configuration
[noi simulation] juice tree (tree DP)
Affected tree (tree DP)
Synchronization of QT multithreading