PDA

View Full Version : C: gets() function warning.


kapok
January 18th, 2009, 07:14 PM
whats dangerous about the gets() function?

jimi_hendrix
January 18th, 2009, 07:25 PM
buffer overflow...use fgets() instead

kapok
January 18th, 2009, 07:26 PM
fgets() works the same way?

jimi_hendrix
January 18th, 2009, 07:30 PM
myString = fgets(myString, sizeof(string), stdin);
/*takes a string, how many chars to read, and the file (in this case stdin for cli input) to read returns the value of the string you pass so i think what i have up there is redundent*/

module0000
January 18th, 2009, 08:29 PM
Can ram as many characters into gets() input as you want, eventually writing to memory you have no business writing to.