It seems to me, people, especially when learning the C programming language, are still using the gets
function to read in data from stdin. Despite that it has now been removed1 from the C11 standard, and a disclaimer on cppreference reads:
The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear on stdin). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard. fgets() and gets_s() are the recommended replacements.
Never use gets().
However, it seems to be that this is not a new issue that came up with more modern programming philosophies. It would have always been broken and have caused programs to crash and I don't see what could possibly be meant by an "environment which restricts what can appear on stdin".
So, was it ever useful in the past? Or what is the reason it was added to previous standards and pre-standard versions of C?
(1) ... or at least changed to have an additional parameter indicating the maximal length to read. I am however asking about the old signature, receiving only a pointer.
&&
to those criteria. You seem to be applying||
. :-) There's no "actual problem" here. I didn't make the rules of SO (and it would be a different place if I had), I'm just pointing them out. – Horsewhipgets
amongst beginners is an actual problem that we all face, so I don't see your point nor your VTC. – Annuletgets
practical for?" Currently it's not possible to answer without defining "useful" and is likely to solicit debate, arguments or extended discussion. If you want the question re-opened, it needs to be factually answerable. – Flyweight