Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gets() function is not available in Visual studio 2015 community

I have faced a compiler error(c3861) in my newly installed Visual studio community 2015 IDE:

I just want to use gets() function from stdio.h library, and i have included stdio.h file in my program, but compiler show me a compiler error like below:

error C3861: 'gets': identifier not found 

What should i do to compile my program correctly withgets() function.

like image 291
maruf Avatar asked Aug 29 '15 07:08

maruf


2 Answers

if you are looking forward to learn about

buffer overflow vulnerability

you simply can use it and anther unsafe functions by the fallowing steps

  1. from the solution explorer right click on the project and choose properties
  2. navigate to Configuration Properties >> C/C++ >> Advanced
  3. change Compile As value to Compile as C Code (/TC)
  4. (optional) if you would like to disable the warning just put its warning number in disable specific warning
like image 199
Basheer AL-MOMANI Avatar answered Oct 13 '22 01:10

Basheer AL-MOMANI


Since C11, gets is replaced by gets_s. The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflows. The recommended replacements are gets_s() or fgets()

gets_s(buf);
fgets(buf, sizeof(buf), stdin);
like image 33
Kurt Van den Branden Avatar answered Oct 13 '22 02:10

Kurt Van den Branden