メインコンテンツ

MISRA C:2012 Rule 4.1

Octal and hexadecimal escape sequences shall be terminated

説明

ルール定義

Octal and hexadecimal escape sequences shall be terminated 1 .

根拠

8 進数または 16 進数エスケープ シーケンスの直後に他の文字が続くと混乱を招く可能性があります。たとえば、文字定数 '\x1f' は 1 文字で構成され、文字定数 '\x1g''\x1''g' の 2 文字で構成されています。複数文字定数を整数として表現する方法は、処理系定義です。

文字定数または文字列リテラルのすべての 8 進数または 16 進数のエスケープ シーケンスが終了していれば、混乱を招く可能性は低くなります。

トラブルシューティング

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

すべて展開する

この例では、エスケープ シーケンスが文字列リテラルの終端か別のエスケープ シーケンスで終了していない場合、ルールに違反します。

const char *s1 = "\x41g";     /* Non-compliant */
const char *s2 = "\x41" "g";  /* Compliant - Terminated by end of literal */
const char *s3 = "\x41\x67";  /* Compliant - Terminated by another escape sequence*/

const char *c1 = "\1412";   /* Non-compliant */
const char *c2 = "\141\t";  /* Compliant - Terminated by another escape sequence*/

チェック情報

グループ: 文字セットおよび構文規則
カテゴリ: 必要
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.