このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
MISRA C:2012 Rule 21.19
The pointers returned by the Standard Library functions localeconv
, getenv
, setlocale
or strerror
shall only be used as if they have pointer to const
-qualified type
説明
ルール定義
The pointers returned by the Standard Library functions localeconv
, getenv
, setlocale
or strerror
shall only be used as if they have pointer to const
-qualified type. 1
This rule comes from MISRA C™:2012 Amendment 1.
根拠
C99 規格によると、localeconv
によって返される値が指す構造体、または getenv
、setlocale
、strerro
によって返される文字列をプログラムで変更すると、未定義の動作が発生します。さまざまな関数によって返されるポインターを const
修飾子付きかのように扱うことで、解析ツールはいずれかのポインター経由でのオブジェクトの変更の試みを検出できます。関数の戻り値を const
修飾子付きのポインターに代入することで、オブジェクトを変更しようとした場合に、コンパイラで診断が行われるようになります。
Polyspace 実装
以下の関数の出力を const
でないポインターに代入する場合、Polyspace® はこのルールの違反を報告します。
localeconv
,getenv
,setlocale
,strerror
トラブルシューティング
ルール違反を想定していてもその違反が表示されない場合、コーディング規約違反が想定どおりに表示されない理由の診断を参照します。
例
チェック情報
グループ: 標準ライブラリ |
カテゴリ: Mandatory |
AGC カテゴリ: Mandatory |
バージョン履歴
R2017a で導入参考
MISRA C:2012 Rule 7.4
| MISRA C:2012 Rule 11.8
| MISRA C:2012 Rule 21.8
| MISRA C:2012 のチェック (-misra3)
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.