...
Confusing narrow and wide character strings can result in buffer overflows, data truncation, and other defects.
Rule | Severity | Likelihood | Detectable | RepairableRemediation Cost | Priority | Level |
|---|---|---|---|---|---|---|
STR38-C | High | Likely | Yes | NoLow | P27P18 | L1 |
Automated Detection
Modern compilers recognize the difference between a char * and a wchar_t *, so compiling code that violates this rule will generate warnings. It is feasible to have automated software that recognizes functions of improper width and replaces them with functions of proper width (that is, software that uses wcsncpy() when it recognizes that the parameters are of type wchar_t *).
Tool | Version | Checker | Description | ||||||
| Astrée |
| wide-narrow-string-cast wide-narrow-string-cast-implicit | Partially checked | ||||||
| Axivion Bauhaus Suite |
| CertC-STR38 | Fully implemented | ||||||
| Clang |
| -Wincompatible-pointer-types | |||||||
| CodeSonar |
| LANG.MEM.BO | Buffer Overrun | ||||||
| Coverity |
| PW | Implemented | ||||||
| Cppcheck Premium |
| premium-cert-str38-c | |||||||
| Helix QAC |
| C0432 C++0403 | |||||||
| Klocwork |
| CXX.DIFF.WIDTH.STR_AND_FUNC | |||||||
| Parasoft C/C++test |
| CERT_C-STR38-a | Do not confuse narrow and wide character strings and functions | ||||||
| PC-lint Plus |
| 2454, 2480, 2481 | Partially supported: reports illegal conversions involving pointers to char or wchar_t as well as byte/wide-oriented stream inconsistencies | ||||||
| Polyspace Bug Finder |
| Checks for misuse of narrow or wide character string (rule fully covered) | |||||||
| RuleChecker |
| wide-narrow-string-cast wide-narrow-string-cast-implicit | Partially checked | ||||||
| Security Reviewer - Static Reviewer |
| UNSAFE_02 | Fully implemented | ||||||
| TrustInSoft Analyzer |
| pointer arithmetic | Partially verified. |
...