メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

MISRA C:2012 Rule 22.3

The same file shall not be open for read and write access at the same time on different streams

説明

ルール定義

The same file shall not be open for read and write access at the same time on different streams 1 .

根拠

ファイルに対し読み取りと書き込みの両方が別々のストリームで行われた場合、その動作は未定義となることがあります。

Polyspace 実装

このルールは Bug Finder 解析でのみチェックできます。

トラブルシューティング

ルール違反を想定していてもその違反が表示されない場合、コーディング規約違反が想定どおりに表示されない理由の診断を参照します。

すべて展開する

#include <stdio.h>

void func(void) {
    FILE *fw = fopen("tmp.txt", "r+");
    FILE *fr = fopen("tmp.txt", "r");   /* Non-compliant: File open in stream fw*/
}

この例では、同じファイル tmp.txt が 2 つのストリームで開かれる場合に、このルールに違反しています。FILE ポインター fw および fr は、ここでは 2 つの異なったストリームを指しています。

チェック情報

グループ: Resources
カテゴリ: 必要
AGC カテゴリ: 必要

バージョン履歴

R2015b で導入


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.