Use of an obsolete / deprecated function
ID |
c.maintainability.obsolete_function |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Deprecated Api |
Language |
C / C++ |
Description
This function is obsolete: it has been removed from POSIX or deprecated in favour of a modern equivalent (e.g. bcopy/bzero/bcmp → memmove/memset/memcmp, index/rindex → strchr/strrchr, usleep/ualarm → nanosleep, gcvt/ecvt/fcvt → snprintf). Replace it with the standard equivalent for portability and clarity.
Rationale
This function is obsolete: it has been removed from POSIX or deprecated in favour of a modern equivalent (e.g. bcopy/bzero/bcmp → memmove/memset/memcmp, index/rindex → strchr/strrchr, usleep/ualarm → nanosleep, gcvt/ecvt/fcvt → snprintf). Replace it with the standard equivalent for portability and clarity.
The following code illustrates the pattern detected by this rule:
void legacy(char *dst, const char *src, int n) {
// FLAGGED: Use of an obsolete / deprecated function
bcopy(src, dst, n);
// FLAGGED: Use of an obsolete / deprecated function
bzero(dst, n);
// FLAGGED: Use of an obsolete / deprecated function
if (bcmp(src, dst, n) == 0) return;
// FLAGGED: Use of an obsolete / deprecated function
char *p = index(src, '/');
// FLAGGED: Use of an obsolete / deprecated function
char *q = rindex(src, '/');
// FLAGGED: Use of an obsolete / deprecated function
usleep(1000);
(void)p; (void)q;
}