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.TOKEN.UNTERMINATED.ESCAPE.2012

Octal and hexadecimal escape sequences shall be terminated

MISRA C 2012 Rule 4.1: Octal and hexadecimal escape sequences shall be terminated

C90 [Implementation 11], C99 [Implementation J.3.4(7, 8)]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

An octal or hexadecimal escape sequence shall be terminated by either:
  • The start of another escape sequence, or
  • The end of the character constant or the end of a string literal.

Rationale

There is potential for confusion if an octal or hexadecimal escape sequence is followed by other characters. For example, the character constant '\x1f' consists of a single character whereas the character constant '\x1g' consists of the two characters '\x1' and 'g'. The manner in which multi-character constants are represented as integers is implementation-defined.

The potential for confusion is reduced if every octal or hexadecimal escape sequence in a character constant or string literal is terminated.

Example

In this example, each of the strings pointed to by s1, s2 and s3 is equivalent to “Ag”.

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 */

int c1 = '\141t';            /* Non-compliant                            */ 
int c2 = '\141\t';           /* Compliant - terminated by another escape */

See also

C90: Section 6.1.3.4, C99: Section 6.4.4.4