Menu

CharVar

Daniel Marjamäki

Dangerous usage of char variables

Using char variables is not always safe.

char s8 = 0xff;

char ch1 = str[s8];    // str[s8] = str[0xffffffff]
int result1 = 1 | s8;  // 1 | s8 => 1 | 0xffffffff

cppcheck detects these problems.

There will be false positives if either:
- It's the intended behaviour
- You know the variable will never have dangerous values

Because of the false positives, this check is in the "--all" checks.


Related

Wiki: ListOfChecks