メインコンテンツ

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

MISRA C:2012 Rule 21.6

The Standard Library input/output functions shall not be used

説明

ルール定義

The Standard Library input/output functions shall not be used 1 .

根拠

このルールは <stdio.h> により提供される関数に適用され、C99 では <wchar.h> により提供される同等のワイド文字の関数に適用されます。これらの関数を使用すると、未指定、未定義、処理系定義の動作が発生する可能性があります。

Polyspace 実装

ファイルおよびストリームの入力/出力関数を <stdio.h> および <wchar.h> ヘッダー ファイルから呼び出す場合、Polyspace® は違反を報告します。標準ライブラリ関数がマクロであり、そのマクロがコード内で展開される場合は、このルールに違反します。Polyspace は、ルール 21.2 に違反していないことを前提とします。

トラブルシューティング

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

すべて展開する

この例では、関数 func() が各種のファイルとストリームの入力/出力関数をヘッダー ファイル <stdio.h> および <wchar.h> から呼び出します。Polyspace は、これらの関数の使用に対してこのルールの違反を報告します。

#include <stdio.h>
#include <wchar.h>

void mixed_io_example() {
    // Define a buffer for wide characters
    wchar_t wbuffer[50];

    // Read a wide string from standard input
    wprintf(L"Enter a wide string: "); // Noncompliant
    fgetws(wbuffer, 50, stdin); // Noncompliant

    // Print the wide string using wide character output
    wprintf(L"You entered: %ls", wbuffer); // Noncompliant

    // Define a buffer for regular characters
    char buffer[50];

    // Read a regular string from standard input
    printf("Enter a regular string: "); // Noncompliant
    fgets(buffer, 50, stdin); // Noncompliant

    // Print the regular string using regular character output
    printf("You entered: %s", buffer); // Noncompliant
}

チェック情報

グループ: 標準ライブラリ
カテゴリ: 必要
AGC カテゴリ: 必要

バージョン履歴

R2014b で導入

すべて展開する


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.