当前位置:网站首页>On the insecurity of using scanf in VS
On the insecurity of using scanf in VS
2022-04-23 14:25:00 【KissKernel】
# About the vs Use in scanf The problem of insecurity
### First of all scanf Why is it not safe
The first is about memory overflow ,scanf The length of the string you enter will not be detected when using, so there is a risk of memory overflow .
#include<stdio.h>
int main()
{
char arr[6]={
0};
scanf("%s",&arr);
// Assume that the input helloworld There will be the problem of cross-border visits , therefore scanf In this case, it will not be safe .
}
### The second is how to solve scanf The problem of insecurity
There are two ways to solve this problem
1. One is to open vs project Options see the last option attribute
take SDL Check disable
2. In the file .c Insert the following code in the first line of the ;
#define _CRT_SECURE_NO_WARNINGS
Inserting at the beginning of each file is obviously a little cumbersome , So there's another way... Once and for all , Let me introduce it . First find your vs Install path to find this file newc++file.c Copy it to the desktop, and then copy the above code in , Then copy this file back to the original path . Replace the original file .* So why don't you do it here , Because when you change directly in the original path newc++file.c You will be prompted that you do not have permission to change .
### Finally, why scanf_s Security
vs Provided in scanf_s The function needs to specify the number of input characters , So you need to enter an additional qualified number . This ensures that the function will not access beyond the bounds .
#include<stdio.h>
int main()
{
char arr[6];
scanf_s("%s",&arr,5);// Then there will be no unexpected cross-border visits at this time
return 0;
}
There will only be man-made cross-border access, such as you have to enter hello Five characters only define arr[5] So the end of the string \0; It will cross the border because there is no place to place it .
Of course, I still recommend using... In daily programming scanf because scanf_s yes vs If you write it yourself, it will report errors in other compilers , Poor reusability .
I uploaded all the above files in my code cloud , You can see what you need
link
版权声明
本文为[KissKernel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412251974.html
边栏推荐
- 555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
- 统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
- How does void * exist?
- Get the thread return value. Introduction to the use of future interface and futuretask class
- 本以为能躺着进华为,结果陆续收到京东/滴滴/爱奇艺offer的我迷茫了
- 剑指offer刷题(1)--面向华为
- 单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
- JS format time
- How to do a project easily
- 逻辑卷创建与扩容
猜你喜欢
循环队列的基本操作(实验)
处理 mkdir:无法创建目录“aaa“:只读文件系统
数组模拟队列进阶版本——环形队列(真正意义上的排队)
电子秤称重系统设计,HX711压力传感器,51单片机(Proteus仿真、C程序、原理图、论文等全套资料)
ArrayList集合基本使用
爬虫练习题(一)
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
顺序表的操作,你真的学会了吗?
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
随机推荐
flannel 原理 之 TUN模式
51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等
LM317的直流可调稳压电源Multisim仿真设计(附仿真+论文+参考资料)
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
解决ssh配置文件优化以及连接慢的问题
C语言知识点精细详解——数据类型和变量【2】——整型变量与常量【1】
KVM学习资源
Solve the problem of SSH configuration file optimization and slow connection
ansible及常用模块的使用
redis的五种数据类型
async void 导致程序崩溃
初始c语言大致框架适合复习和初步认识
顺序表的操作,你真的学会了吗?
修改Firebase Emulators的默认侦听IP
Use cases of the arrays class
Processing MKDIR: unable to create directory 'AAA': read only file system
x509证书cer格式转pem格式
Man man notes and @ reboot usage of crontab
Qt实战:云曦日历篇
Qt界面优化:鼠标双击特效