Main Content

ISO/IEC TS 17961 [filecpy]

Copying a FILE object

Description

Rule Definition

Copying a FILE object.1

Polyspace Implementation

This checker checks for Dereferencing a FILE* pointer.

Examples

expand all

Issue

The issue occurs when a pointer to a FILE object is dereferenced.

Risk

The Standard states that the address of a FILE object used to control a stream can be significant. Copying that object might not give the same behavior. This rule ensures that you cannot perform such a copy.

Directly manipulating a FILE object might be incompatible with its use as a stream designator.

Example - FILE* Pointer Dereferenced
#include <stdio.h>

void func(void) {
    FILE *pf1;
    FILE *pf2;
    FILE f3;

    pf2 = pf1;        /* Compliant */
    f3 = *pf2;        /* Non-compliant */
    pf2->_flags=0;    /* Non-compliant */
 }

In this example, the rule is violated when the FILE* pointer pf2 is dereferenced.

Check Information

Decidability: Undecidable

Version History

Introduced in R2019a


1 Extracts from the standard "ISO/IEC TS 17961 Technical Specification - 2013-11-15" are reproduced with the agreement of AFNOR. Only the original and complete text of the standard, as published by AFNOR Editions - accessible via the website www.boutique.afnor.org - has normative value.