Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.FILE_PTR.DEREF.INDIRECT.2012

A pointer to a FILE object (returned by a function) shall not be dereferenced.

MISRA C 2012 Rule 22.5: A pointer to a FILE object shall not be dereferenced

Category: Mandatory

Analysis: Undecidable, System

Applies to: C90, C99

Amplification

A pointer to a FILE object shall not be dereferenced directly or indirectly (e.g. by a call to memcpy or memcmp).

Rationale

The Standard (C90 Section 7.9.3(6), C99 Section 7.19.3(6) ) states that the address of a FILE object used to control a stream may be significant and a copy of the object may not give the same behaviour. This rule ensures that such a copy cannot be made.

The direct manipulation of a FILE object is prohibited as this may be incompatible with its use as a stream designator.

Example

#include <stdio.h>

FILE *pf1; 
FILE *pf2; 
FILE f3;

pf2 = pf1;     /* Compliant */ 
 f3 = *pf2;    /* Non-compliant */

The following example assumes that FILE * specifies a complete type with a member named pos:

pf1->pos = 0;    /* Non-compliant */

See also

Rule 21.6