Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Deprecated Functions

The gets() function was deprecated by Technical Corrigendum 3 to C99 and eliminated from C11.

...

Many of these functions are obsolete because they lack robust error-handling capabilities.  See ERR07-C. Prefer functions that support error checking over equivalent functions that don't and INT05-C. Do not use input functions to convert character data if they cannot handle all possible inputs.

The fopen() and freopen() functions are obsolete because the fopen_s() and freopen_s() functions in C11 Annex K can emulate their usage and improve security by protecting the file from unauthorized access by setting its file protection [ISO/IEC 9899:2011].

The asctime() and ctime() functions are obsolete because they use non-reentrant static buffers and can be emulated using asctime_s() and ctime_s().

Unchecked Obsolete Functions

...

In this noncompliant code example, the obsolete functions strcat() and strcpy() are used:

Code Block
bgColor#FFcccc
#include <string.h>
#include <stdio.h>
 
enum { BUFSIZE = 32 };
void complain(const char *msg) {

  static const char prefix[] = "Error: ";
  static const char suffix[] = "\n";
  char buf[BUFSIZE];

  strcpy(buf, prefix);
  strcat(buf, msg);
  strcat(buf, suffix);
  fputs(buf, stderr);
}

...

Code Block
bgColor#ccccFF
langc
#define __STDC_WANT_LIB_EXT1__
#include <string.h>
#include <stdio.h>
 
enum { BUFFERSIZE = 256 };

void complain(const char *msg) {
  static const char prefix[] = "Error: ";
  static const char suffix[] = "\n";
  char buf[BUFFERSIZE];

  strcpy_s(buf, BUFFERSIZE, prefix);
  strcat_s(buf, BUFFERSIZE, msg);
  strcat_s(buf, BUFFERSIZE, suffix);
  fputs(buf, stderr);
}

...