warning:this program uses gets(), which is unsafe
来源:互联网 发布:提升店铺流量软件 编辑:程序博客网 时间:2024/05/18 05:04
1. 在C语言编程中使用gets(), 编译时会出现如下警告:
warning: this program uses gets(), which is unsafe.
gets()不安全是因为你给了他一个缓冲区,但是你却没有告诉它这个缓冲区到底有多大,也不知道输入的内容到底有多大,输入的内容可能超出缓冲区的结尾,引起你的程序崩溃,使用fgets会好一些,因为你会指定它的缓冲区大小,如下面一段代码:
char buffer[bufsize];
fgets(buffer, bufsize, stdin);
2. fgets
原型:char* fgets(char *buf, int bufsize, FILE *stream);
buf:字符型指针,指向用来存储所得数据的地址
bufsize:整形数据,指明缓冲区的大小,拷贝到buf地址的最大字符数量
stream:指明输入流的FILE对象的指针,stdin可以作为参数,表示从标准输入读取
返回值:成功,则函数返回buff
如果当尝试读取一个字符时遇到了文件结尾,则eof被置位(feof),如果还没有成功读入任何一个字符就遇到了文件结尾,那么就会返回null,buff中的内容保持不变。如果读取错误发生,那么error indicator(ferror)被置位,还是返回null
0 0
- warning: this program uses gets(), which is unsafe.
- warning:this program uses gets(), which is unsafe
- this program uses gets(), which is unsafe.
- this program uses gets(), which is unsafe.
- c中使用gets() 提示warning: this program uses gets(), which is unsafe.
- C语言(Bug) warning: this program uses gets(), which is unsafe.
- warning C4996: 'gets': This function or variable may be unsafe. Consider using gets_s instead.
- 警告 1 warning C4996: 'gets': This function or variable may be unsafe.类似情况
- warning: its scope is only this definition or declaration, which is not what you want
- This is C++ program
- compile c++ program which uses stl in ndk
- This is my first program
- This is a C++ program
- mysql 警告提示Unsafe statement .The statement is unsafe because it uses a LIMIT clause
- warning C4996: 'strcpy': This function or variable may be unsafe.
- warning C4996: 'sprintf': This function or variable may be unsafe.
- warning C4996: 'fopen': This function or variable may be unsafe
- What causes javac to issue the “uses unchecked or unsafe operations” warning
- pageContext.pushBody() getOutputStream方法冲突
- linux中串口如何支持非标准波特率B28800?
- Android中Parcelable接口用法
- mac 生成 ssh keys
- ip
- warning:this program uses gets(), which is unsafe
- JSP和Servlet
- Android 文字粗体设置方法
- SQL注入网址
- Chrome内核解析 -- 背景篇:HTML, CSS解析与JavaScript执行
- 紫外线消毒器:紫外线消毒器水力特性研究介绍
- 服务器部署java web项目
- stl之再看迭代器(traits特性分析)
- 【Android 应用开发】 Android APK 反编译 混淆 反编译后重编译