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/bcmpmemmove/memset/memcmp, index/rindexstrchr/strrchr, usleep/ualarmnanosleep, gcvt/ecvt/fcvtsnprintf). 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/bcmpmemmove/memset/memcmp, index/rindexstrchr/strrchr, usleep/ualarmnanosleep, gcvt/ecvt/fcvtsnprintf). 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;
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.