JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


PARSE.BAD.CV : Bad Character Value

Summary

A character is specified with an octal or hexadecimal escape sequence whose value is too large to fit into the character type used.

This warning class is derived from a C/C++ parser warning.

Properties

Class Name Bad Character Value
Significance style
Mnemonic PARSE.BAD.CV
Categories
Misra2004 Misra2004:4.1 Only those escape sequences that are defined in the ISO C standard shall be used
AUTOSARC++14 AUTOSARC++14:A2-13-1 Only those escape sequences that are defined in ISO/IEC 14882:2014 shall be used.
MisraC++2008 MisraC++2008:2-13-1 Only those escape sequences that are defined in ISO/IEC 14882:2003 shall be used.
MisraC++2023 MisraC++2023:5.13.1 Within character literals and non raw-string literals, \ shall only be used to form a defined escape sequence or universal character name
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. However, warning instances of this class that are issued as parser errors (rather than parser warnings) will be discarded when using factory configuration settings. To prevent these instances from being discarded, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Bad Character Value"
To disable checks for this warning class, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Bad Character Value"

Example

#include <stddef.h>

/* Comments on this file reflect a platform with 8-bit char and 32-bit wchar_t.
 * - If your platform has narrower character types you may see additional warnings with the same code.
 * - If your platform has wider character types you may see fewer warnings with the same code.
 */
char invalid_hex_char = '\x100';            /* 'Bad Character Value' warning issued here
                                             * - 0x100 does not fit in an 8-bit char
                                             */
char no_hex_char = 'h';                                         /* ok: no hex escape sequence */
char valid_hex_char = '\x006A';                                 /* ok: 0x6A fits in an 8-bit char */
wchar_t invalid_hex_wchar = L'\x100000000'; /* 'Bad Character Value' warning issued here
                                             * - 0x100000000 does not fit in a 32-bit wchar_t
                                             */
wchar_t valid_hex_wchar = L'\x100';                             /* ok: 0x100 fits in a 32-bit wchar_t */


char valid_oct_char = '\0';                                     /* ok: 0 fits into an 8-bit char */
char invalid_oct_char = '\777';             /* 'Bad Character Value' warning issued here
                                             * - 0777 does not fit in an 8-bit char
                                             */

void myfunc(char *s);

void call_myfunc(void){
    myfunc("hello \x100");                  /* 'Bad Character Value' warning issued here
                                             * - 0x100 does not fit in an 8-bit char
                                             */
    myfunc("hello again");                                      /* ok: no hex escape sequences */
    myfunc("hello yet again \x006A \x41");                      /* ok: both 0x6A and 0x41 fit in an 8-bit char */
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.