Is gets () officially deprecated?

Based on the most recent C ++ 11 project , C ++ refers to ISO / IEC 9899: 1999 / Cor.3: 2007 (E) for the definitions of C library functions (according to § 1.2 [intro.refs] / 1).

Based on the latest draft C99 TC3, The gets function is obsolescent, and is deprecated.(for §7.26.9 / 2)

Is it safe to say that it is gets()deprecated in both C and C ++?

+5
source share
5 answers

Does it matter? The only way to use getsit is if stdin, as you know, it is attached to a file whose contents you have full control over. This condition is almost impossible to satisfy, especially in multiprocessor systems, where other processes can modify files asynchronously with respect to your program. Therefore, for all practical purposes, any program using getshas undefined behavior (i.e., possible inputs / environmental conditions for which it will have undefined behavior), and in particular UB, which can lead to a compromise of privileges if your program has more higher privileges than data provider.

Edit: OK, here is one safe use gets, the only one that I can think of right away ...

if (feof(stdin)) gets(buf);

, - (, glibc..?) , EOF , ....

+2

, , . , , , , .

+4

, gets() , , . , " ", , , , , , "" build.

+1

, ++ 11 .

, C99.

Microsoft, , .

, C, ++.

0

, C11, "".

0
source

All Articles