当前位置:网站首页>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
边栏推荐
- 查找水仙花数-for循环实践
- Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
- uni-app消息推送
- MySQL基础知识
- c语言在结构体传参时参数压栈问题
- 基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
- 矩阵交换行列
- Preview CSV file
- 电子秤称重系统设计,HX711压力传感器,51单片机(Proteus仿真、C程序、原理图、论文等全套资料)
- setcontext getcontext makecontext swapcontext
猜你喜欢

SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)

剑指offer刷题(1)--面向华为

redis的五种数据类型

A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios

Detailed explanation of SAR command

C语言知识点精细详解——数据类型和变量【1】——进位计数制

差分隐私(背景介绍)

KVM learning resources

Man man notes and @ reboot usage of crontab

微信小程序将原生请求通过es6的promise来进行优化
随机推荐
字节面试编程题:最小的K个数
Pass in external parameters to the main function in clion
C语言知识点精细详解——初识C语言【1】
TLC5615 based multi-channel adjustable CNC DC regulated power supply, 51 single chip microcomputer, including proteus simulation and C code
AT89C52单片机的频率计(1HZ~20MHZ)设计,LCD1602显示,含仿真、原理图、PCB与代码等
百度笔试2022.4.12+编程题目:简单整数问题
剑指offer刷题(2)--面向华为
Proteus simulation design of DC adjustable regulated power supply (with simulation + paper and other data)
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
单片机的函数信号发生器,输出4种波形,频率可调,原理图,仿真和C程序
Four ways of SSH restricting login
LLVM - 生成for循环
Use cases of the arrays class
bc的用法
修改Firebase Emulators的默认侦听IP
四层和八层电梯控制系统Proteus仿真设计,51单片机,附仿真和Keil C代码
async void 导致程序崩溃
XX project structure notes
uni-app消息推送
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等